From patchwork Tue Nov 22 20:57:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 627517 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp2723417pvb; Tue, 22 Nov 2022 12:58:33 -0800 (PST) X-Google-Smtp-Source: AA0mqf5pc5lJi1MIvzUcDfTtkGjKVLWNXdFbFvwC9JPtuzMQMg8yWHOiQCoPWtzs9Vogvcv5j+RS X-Received: by 2002:a05:622a:4891:b0:3a5:280a:3c9c with SMTP id fc17-20020a05622a489100b003a5280a3c9cmr7931185qtb.282.1669150713197; Tue, 22 Nov 2022 12:58:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669150713; cv=none; d=google.com; s=arc-20160816; b=qIHGnYELj+VxFr0FFMOFO5bkAIKZLXcK6fzMJiQSFezisHU0wzQLts2wTvXU/b+s6w 16bwxQswVPp/kZRheYxNutXERfIynP+O5MFZSl7/g/G0N+t1askcGFMLUSm1Kvts2I00 Z6z1Tl8x78c4Wto9Q8uYEmhhfcZf8S0S0Yf36j5G2d5YGtF+ZuiQn0tXUrSRSS2y/xFm vIGGX2y2NrtXIw9FHi24HfGLzJLvmjxREhZuBRIoOI2VvJszX35THFB4dLZ7eTYl67Ow ILPReUnXbmD6fYX/jh1RlsYm+ao6F0wI9orEEmORsOZoqVqWz0lynwCDM4ct7lqJWLTU OwuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jYJr4MboKWNHHDRIY0tG/HwSzvYPNM+yCVJFiR1T/6U=; b=nf1XBYi+kzxcFj7IqFz/j9loFRlaUgR3yAjsSWndp0HLtQF9u9bnjvqMdF5vL7QrDS Y0LlhVbfi5Z81c+8fji4bcsNT0VvVhEWF/f0AeXRYXsmAr2QuzOcRIGT41v+WYC4xMhy 8YUHFpjwu3P0BTl9gO5CjW5I1ZThUxEq2e6DXWKUt1N0SwsBvHbEEwtpIaKZMN0BlW50 z4zmPFvZkTpOikzYHo2zlmrBkKutAF2OISTFIpBQyRkN0eQTfQZsKmDZ6fWTkzg2eNAx H3Rj+BKPXfjaFEzx41YWQprweB8FFNqe4DPguQicbxETaD95lh4THUnTC/JAjIHpu9d1 QShQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="yIQweY/x"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id y19-20020a05620a44d300b006fa76ffe62esi10087275qkp.340.2022.11.22.12.58.33 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 22 Nov 2022 12:58:33 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="yIQweY/x"; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oxaL2-0007N6-V9; Tue, 22 Nov 2022 15:57:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oxaL1-0007LS-Da for qemu-devel@nongnu.org; Tue, 22 Nov 2022 15:57:51 -0500 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oxaKz-0003VP-Hz for qemu-devel@nongnu.org; Tue, 22 Nov 2022 15:57:51 -0500 Received: by mail-pj1-x102d.google.com with SMTP id ci10so8054981pjb.1 for ; Tue, 22 Nov 2022 12:57:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jYJr4MboKWNHHDRIY0tG/HwSzvYPNM+yCVJFiR1T/6U=; b=yIQweY/x3WAaQEb3kMCyWN3gVf2imWNtjuaLviMlwsfuJBX9tWdqVjlU2IBqq2E5xP Sq4QXlJE3k3YDxPhn85QE/D6RpY8GnWzk5EPwbOO3gmAlvDWY/SJRbN7irtsrSQUNLLh UO9bM/jMvNU43imhqnQAOUZes8xdqJQEuA/ktkKGqClI6W4Qh+6CHIe8Zs/HHUxx6FYy 52cXWUDt/AyAsEOcrzt5gPyTmt9MSZ+IaHn9oRExnZnVoR/j+F01qCogrkRrZtOoLvdL UQBJi5twe2SuF3tokzVc++mLcLvBMT/o8yLyTjUpgMXl2VvthKOXroh2y86jWYt3MuZN ZKUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jYJr4MboKWNHHDRIY0tG/HwSzvYPNM+yCVJFiR1T/6U=; b=jFfUduh5Ix0BPiUv2WvGT5ymbeAWoNFcpXPpa30u3FrHhdD/r5ngkSqx7OCkV1ui9m S1ec/0Lce13qMaYv/1cYZp7G524QO9tOiOPeoChV15kMwlkEopvVEdyPSRfVqjJKF8xv 2AACffu3bjOPUGkmD0e/b1XeywsXmUbPUrjM9W6J3L6OyhC5/zK02tZaXh8kaUojfpDu omR+h+AdN080KHvz241SEBrFCDiR02W9+1Hh95+9act4ZML2/Z8voCqqkVmIVbAxMml5 jk5rG5qZjtnkQvuCCd3gcitZFczCOmUwzhIB23APGV9BR1BlS+PAlTGsbgG+LcpxMH9K JYHA== X-Gm-Message-State: ANoB5plHpEsDBYGt4Qiaq8PjutXtE4WFjLziPtjQXY32MbuRYIcpptkO kTVlxnv7KYGwSu73Z63C+GtGSvERWqNpOw== X-Received: by 2002:a17:902:e80f:b0:188:f571:cea2 with SMTP id u15-20020a170902e80f00b00188f571cea2mr8808245plg.146.1669150668241; Tue, 22 Nov 2022 12:57:48 -0800 (PST) Received: from stoup.. ([2602:47:d48a:1201:90f5:6f8b:e78a:4a0]) by smtp.gmail.com with ESMTPSA id d19-20020a170903209300b00186fa988a13sm12383807plc.166.2022.11.22.12.57.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 12:57:47 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, philmd@linaro.org, alex.bennee@linaro.org Subject: [PATCH v2 7/7] accel/tcg: Use WITH_QEMU_IOTHREAD_LOCK in io_readx/io_writex Date: Tue, 22 Nov 2022 12:57:39 -0800 Message-Id: <20221122205739.603510-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221122205739.603510-1-richard.henderson@linaro.org> References: <20221122205739.603510-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Narrow the scope of the lock to the actual read/write, moving the cpu_transation_failed call outside the lock. Reviewed-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- accel/tcg/cputlb.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 6f1c00682b..8b86b70c60 100644 --- a/accel/tcg/cputlb.c +++ b/accel/tcg/cputlb.c @@ -1356,7 +1356,6 @@ static uint64_t io_readx(CPUArchState *env, CPUTLBEntryFull *full, MemoryRegionSection *section; MemoryRegion *mr; uint64_t val; - bool locked = false; MemTxResult r; section = iotlb_to_section(cpu, full->xlat_section, full->attrs); @@ -1367,11 +1366,10 @@ static uint64_t io_readx(CPUArchState *env, CPUTLBEntryFull *full, cpu_io_recompile(cpu, retaddr); } - if (!qemu_mutex_iothread_locked()) { - qemu_mutex_lock_iothread(); - locked = true; + WITH_QEMU_IOTHREAD_LOCK() { + r = memory_region_dispatch_read(mr, mr_offset, &val, op, full->attrs); } - r = memory_region_dispatch_read(mr, mr_offset, &val, op, full->attrs); + if (r != MEMTX_OK) { hwaddr physaddr = mr_offset + section->offset_within_address_space - @@ -1380,10 +1378,6 @@ static uint64_t io_readx(CPUArchState *env, CPUTLBEntryFull *full, cpu_transaction_failed(cpu, physaddr, addr, memop_size(op), access_type, mmu_idx, full->attrs, r, retaddr); } - if (locked) { - qemu_mutex_unlock_iothread(); - } - return val; } @@ -1410,7 +1404,6 @@ static void io_writex(CPUArchState *env, CPUTLBEntryFull *full, hwaddr mr_offset; MemoryRegionSection *section; MemoryRegion *mr; - bool locked = false; MemTxResult r; section = iotlb_to_section(cpu, full->xlat_section, full->attrs); @@ -1427,11 +1420,10 @@ static void io_writex(CPUArchState *env, CPUTLBEntryFull *full, */ save_iotlb_data(cpu, section, mr_offset); - if (!qemu_mutex_iothread_locked()) { - qemu_mutex_lock_iothread(); - locked = true; + WITH_QEMU_IOTHREAD_LOCK() { + r = memory_region_dispatch_write(mr, mr_offset, val, op, full->attrs); } - r = memory_region_dispatch_write(mr, mr_offset, val, op, full->attrs); + if (r != MEMTX_OK) { hwaddr physaddr = mr_offset + section->offset_within_address_space - @@ -1441,9 +1433,6 @@ static void io_writex(CPUArchState *env, CPUTLBEntryFull *full, MMU_DATA_STORE, mmu_idx, full->attrs, r, retaddr); } - if (locked) { - qemu_mutex_unlock_iothread(); - } } static inline target_ulong tlb_read_ofs(CPUTLBEntry *entry, size_t ofs)