From patchwork Fri Dec 30 00:01:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 637833 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp3180514pvb; Thu, 29 Dec 2022 16:12:20 -0800 (PST) X-Google-Smtp-Source: AMrXdXvtc33QCUNqE5+GjrGRXXXhX397cK5FJZRGHlwGN/6oJu0bvqL1iK4tkI8ec+lKmObGrg/w X-Received: by 2002:a05:6214:3da0:b0:531:807d:fdc0 with SMTP id om32-20020a0562143da000b00531807dfdc0mr25967417qvb.28.1672359139860; Thu, 29 Dec 2022 16:12:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672359139; cv=none; d=google.com; s=arc-20160816; b=uCpICEP7wn+GW6wYTnJrbszmUdSxU5z/MwPnxml90SC5UF8s+wQfHEZhtAuujFWKoS GAta8ShngblOAcFP+beDw7LgF6Chr2XTCcIwKjuzRcgymMOZiJIkmmgzX7TJ2Bh9pF2u 6F3Ftw1ktgEElH6ZGiOo6n/W99DrSJyzWhBdcnCpeC+HPs9OgR4Jg9k35wk7cjlReGvf /xKjqLb1aw7V/Bhm1T9hTJ57hkoeb5jekS+nvhZiaaa/1Ah/eMKBmXsUmJa5yfYzEDyE CjiwSE6ucN26atexySfz+ndI3sHjXfT5s4sWwqgATOR4MU1khZymiotDMYw3DAqc2r7M J1lg== 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=yTAFA5u9VpP4tWGyC/Uni1rtwcEMMx/BI1MBDPeSpjQ=; b=yZwPzrMcw2P+J19JM3+PBhuFp0CH9sZUwm3py/vNCnNNXFp7Jk0esVXlI14LaY/RSo fOyu+S59qhj3mLzocGAQFDvpGt2wk6knLnKJYrT+EFjSsV+RMkM27+XpQYb6u0AOkk83 Q8jiaaN0+DU/nwzxekmN4Nhsl3y8KIbepgfYNyQzkZWmhCnbHkNblvJ7wo4cSoKUgfBP s+FKRPe7ufqSyOiUR/C75nsqCPaJ+A78OBLmd0DpmlpS/q+3uTOM8Xo2JIcDchaH6X2V omDjwLWpaE6i/JWfZHKwYOFJ9T6nepZR7TpcGS4m7+9B02nKsJ0qZbkEzqmGjyBOFRcl UrDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ux57F5sV; 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 a9-20020a056214062900b004c644b32afbsi8823372qvx.566.2022.12.29.16.12.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 29 Dec 2022 16:12:19 -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=Ux57F5sV; 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 1pB2r8-000315-7a; Thu, 29 Dec 2022 19:02:38 -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 1pB2r6-0002zk-9e for qemu-devel@nongnu.org; Thu, 29 Dec 2022 19:02:36 -0500 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pB2r4-0002gZ-Ia for qemu-devel@nongnu.org; Thu, 29 Dec 2022 19:02:36 -0500 Received: by mail-pj1-x1033.google.com with SMTP id n65-20020a17090a2cc700b0021bc5ef7a14so20320249pjd.0 for ; Thu, 29 Dec 2022 16:02:34 -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=yTAFA5u9VpP4tWGyC/Uni1rtwcEMMx/BI1MBDPeSpjQ=; b=Ux57F5sVqlCG8QYQDCHCLHXGC9OrJDcdjUG1Oly4PodSzKqDN7CQ3I0BKmzeLEYARC 3NRGBtvOHIkxuqewC/907+ssP1DfQQq7qRUmVYQsj6OUZ02Sm7R0Jtk8QNCt+4wK0tpC pocvlI2RUc3TQhaoByuaozEA+tVFb9X4rZguy1mtaj4hbty1ZwgjYL/bGtvIRFhETw4B Kbla5NTQGzYNL/Q6M8eL/HdChbaT6vCyDn6ixHt0V2/3TDGtLY0qZJT+GusoEmbFdIbw G4J3yvqe0doY/xe+yos49ND9yrnSJthbL+IaCguRV/x1wMkfaOYAavOVEd8ag+KSi3i6 ukNg== 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=yTAFA5u9VpP4tWGyC/Uni1rtwcEMMx/BI1MBDPeSpjQ=; b=zawUmGx5SF+iFOSVY0Cpudb0m7FOUrLNmrjoh9M5ULteEAN6NKRxXPZicFptZadC4Z WrDyDncAwxjxRmajZS+ICaBlj2U3OGuHtFeUvwT+BQ1QnkWpbAm04JAV8Veihxlegb/a VbLE4qIQssyCAEiuKlpB8zIFX30uhoTMJSLikuFDUaez2B83Ogh5R6x2ZhG41EmYR4Qc iUWnJS8/uP64872QSfeg+HcsIsY0nB00dsui+7SAHdHB7p/PKn9WOMRfWcq/L8TrVhEY gYKCqmTurhk5iHp2bBTgkHiN2isfr/vV4Btw8rND7+Nj6oa6BLX++YYXUTj++bi7Y7wK /OyA== X-Gm-Message-State: AFqh2kpzp6xwyqaYP8/4UDD5UPim1BbS3twMRURp3ZWb9mg8zzhh+lI6 3a9nMjH+XVuF+pMfT1urgDsw2M7uwJLuljm9 X-Received: by 2002:a17:902:b609:b0:192:4ed2:7509 with SMTP id b9-20020a170902b60900b001924ed27509mr31905401pls.15.1672358553306; Thu, 29 Dec 2022 16:02:33 -0800 (PST) Received: from stoup.. (76-14-210-194.or.wavecable.com. [76.14.210.194]) by smtp.gmail.com with ESMTPSA id j14-20020a170903028e00b00192849e1d0asm7343953plr.116.2022.12.29.16.02.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Dec 2022 16:02:32 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 11/47] accel/tcg: Use QEMU_IOTHREAD_LOCK_GUARD in io_readx/io_writex Date: Thu, 29 Dec 2022 16:01:45 -0800 Message-Id: <20221230000221.2764875-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221230000221.2764875-1-richard.henderson@linaro.org> References: <20221230000221.2764875-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.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: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- accel/tcg/cputlb.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c index 03674d598f..4948729917 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,11 @@ 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; + { + QEMU_IOTHREAD_LOCK_GUARD(); + 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 +1379,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 +1405,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 +1421,11 @@ 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; + { + QEMU_IOTHREAD_LOCK_GUARD(); + 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 +1435,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)