From patchwork Thu Mar 13 03:44:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 873134 Delivered-To: patch@linaro.org Received: by 2002:a5d:5343:0:b0:38f:210b:807b with SMTP id t3csp271784wrv; Wed, 12 Mar 2025 20:48:04 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCX/4UyRGhpihFPNFKTxbGJDJgYYajmUIt6eXCj/yZVtx3pOuenCdbqgyNcerq/efWRchYSTsA==@linaro.org X-Google-Smtp-Source: AGHT+IHAodeSMz55sl0h0uusPdjkuPKcnMOJvd5oU6lGqoJZ2hFJ8kcvC38vkfDPMf5mtCi1pYvN X-Received: by 2002:a05:622a:1809:b0:476:add4:d2bf with SMTP id d75a77b69052e-476add4d488mr84859171cf.22.1741837684607; Wed, 12 Mar 2025 20:48:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1741837684; cv=none; d=google.com; s=arc-20240605; b=S+hNMiiH+x1KXarOOXU7S+8QmfE8A4raECUEr7aqIP45JXwXnEBEO04hHqu26BMTvY 5I+N+Z8OVj6S6K8oOx40YiQsnxIxFM2p0uUFSUJZANlfeDhDT/hTagNn6BsV+vpbXLT1 JGkU5or4uChDZmIK192YAFBitw4zrV1LzWOIar6Rv7agz2fWpobV87jeua0h/P6UnTnG 1J6smuMHl/8pN5eu2nha8pPsYjloVn03CmAep/SCjMnw8FrjdhZ21wG/C2HLHfg4ldnj qeSN5/M3L0vcWV7mXs5RLOfqF6adAPHQ10qaoFND7GCuEwk7KTSDaoEvxhYoWvP/d30w /a+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=KTz0opqvxfbqwvltJvZBi8g6Tk2gJy+3YsapeLlujac=; fh=DMsE7tt1yctKFfl3yHwu1RCUVEpd9TdAG7FdasYB91k=; b=gwiR5S4VHp8nb2TS5Z4J0GD7YB2pB8gNuqyL8h40NeCyx/KWHzt9UQ71JwDTpGjBWo CCzHxfj6mHLB2lv/2yeQ1QDzb6ss4j/f20U+eav4vhFRND+8gtzZ5L1EZAiHj6m5eBqF 1BiQAkKfAkepxjm8kUTRnk/Tuk7cFIoRHgUE3pwbG0bDeENBvAuBhOivC7/Tcl9TVwTW syCsBJgMLQPsWc1NkUboEb4VLafbksa8y23HYOBUhWBf3tjwA7cw7c+6MzoUofW0ocAu cO9PSI0ItJYZ023hYC2UB8o9sVKqbUD2FcZxak9zdMg37IYm1sUuVOnZzRE+w1TxmSyt jgww==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j2zfo2qQ; 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; dara=neutral header.i=@linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d75a77b69052e-476bb6146a4si8059671cf.117.2025.03.12.20.48.04 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 12 Mar 2025 20:48:04 -0700 (PDT) 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=j2zfo2qQ; 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; dara=neutral header.i=@linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tsZVy-0004bK-VP; Wed, 12 Mar 2025 23:45:47 -0400 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 1tsZVx-0004av-QL for qemu-devel@nongnu.org; Wed, 12 Mar 2025 23:45:45 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tsZVp-0007lc-21 for qemu-devel@nongnu.org; Wed, 12 Mar 2025 23:45:45 -0400 Received: by mail-pj1-x102f.google.com with SMTP id 98e67ed59e1d1-2fecba90cc3so1172659a91.2 for ; Wed, 12 Mar 2025 20:45:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741837533; x=1742442333; darn=nongnu.org; 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=KTz0opqvxfbqwvltJvZBi8g6Tk2gJy+3YsapeLlujac=; b=j2zfo2qQCArmW5qUnQSmYKqoN+A0HDguUp5A4xcXSWi64Z3uXOrCpacGhBYzc+YXa6 Tic1/UGnqYAIwAvAwdwYUvmmDJ7Hp+rP7TU1G8IpGhVWgDtqdE0hS5RiMEKYjM8JrLBm f5urjq5OOi9wEhASlpnU27T53VNFwCXgMyPdBlpiQg3gQgaF2f6EjE0t/nz4zFHNVLVN 0E2pu7sQZ/pNoWfJUE6pm+EXADAhsSFbilgW0qM2v6TPZrPBX1kRopYb8U75h+ULvyiw HE7ILPXebVAvVpV15BKf9r0R708YdUQzc2R3vX8bG7WWKQtrj4moxcgeKczfLvs7bMru 9fTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741837533; x=1742442333; 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=KTz0opqvxfbqwvltJvZBi8g6Tk2gJy+3YsapeLlujac=; b=Fl4OS4P9lPy2Aw08FEH7QjTJQjwCjYCI9RoifteCoyjsr81OZVymoKyQwrmZyVW2sv DEXcM1yLYa8eXNvzQwyVvpwb0PeWnHhAT2m+y6IOuzyYxbOF6tq0EahrNhvnwh/XhDtQ izsEkMbgHv+9XHBzk5tBXPX1z2VuLF69kyKtiSLB9V3RuEXH/+Jr5S/c5BoZdN2vi2EW LPAVIfjdQ6iHVXawuWvxizYmvuIqql/F8aSxuCgw89qhWV064HKgiDiF7slcjJI4rTwq 8ZRJuwW2Xg3heYLSRPsMvlwnMGQZ5aZVsgu4W/t5fDqHkWpIGnXF8e1SY9SKr2nlRZuX 0+IA== X-Gm-Message-State: AOJu0Yz7yWRAQ9AHBYV9cD50r/8r0x0xTxGZTs80utWaw/Ns0TDnxcNi 3z/ElELzBtSFM+NKX6e/45uHryddsLdioJ5M27hUkZFVM2pSRN28agjn2K/Me5bpIHZ7pO1N0DF S X-Gm-Gg: ASbGncszkGHmvSk3UQ0oOKQRt5zeSAvdrjqom4pyXJCdT2osV5BxmYNYHwtypk/zkYZ t1HkW0Y3BYd84o9UN+C0vHZ328ZIk6m2Y8u7ADfrFEmr9pSXuuxFNxk/Gk3G9gUJ9yZpD2sbPQR YGitgNPEYAqlI1lqrPXH8uLp/r9fYSYXe60Dc6xIk2Y8rLN1gtSZ4JAlT2ix6tnBxiF71oqEiJG BcKVk4ZRFF133i46tZTCJcCs4JakKm/5goeuW1dsdtJlHmsAYZq5/FNk/eHYXz4WKPZHWOzWRaq Wev275V4kKBF1cLX4Zrq3fiXJht7B9HBZmpZddhhoSEfhCmx5HwLUxsy9hzOUYZ/AANFIWoW4tO X X-Received: by 2002:a05:6a21:158c:b0:1f5:837b:1868 with SMTP id adf61e73a8af0-1f5837b1902mr21097964637.29.1741837533461; Wed, 12 Mar 2025 20:45:33 -0700 (PDT) Received: from stoup.. (174-21-74-48.tukw.qwest.net. [174.21.74.48]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7371167def8sm316781b3a.90.2025.03.12.20.45.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Mar 2025 20:45:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: pierrick.bouvier@linaro.org, pbonzini@redhat.com, philmd@linaro.org Subject: [PATCH 09/37] accel/tcg: Perform aligned atomic reads in translator_ld Date: Wed, 12 Mar 2025 20:44:49 -0700 Message-ID: <20250313034524.3069690-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250313034524.3069690-1-richard.henderson@linaro.org> References: <20250313034524.3069690-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.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, T_SPF_TEMPERROR=0.01 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 Perform aligned atomic reads in translator_ld, if possible. According to https://lore.kernel.org/qemu-devel/20240607101403.1109-1-jim.shu@sifive.com/ this is required for RISC-V Ziccif. Signed-off-by: Richard Henderson --- accel/tcg/translator.c | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index ef1538b4fc..0260fb1915 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -265,12 +265,14 @@ static bool translator_ld(CPUArchState *env, DisasContextBase *db, if (likely(((base ^ last) & TARGET_PAGE_MASK) == 0)) { /* Entire read is from the first page. */ - memcpy(dest, host + (pc - base), len); - return true; + goto do_read; } if (unlikely(((base ^ pc) & TARGET_PAGE_MASK) == 0)) { - /* Read begins on the first page and extends to the second. */ + /* + * Read begins on the first page and extends to the second. + * The unaligned read is never atomic. + */ size_t len0 = -(pc | TARGET_PAGE_MASK); memcpy(dest, host + (pc - base), len0); pc += len0; @@ -329,7 +331,39 @@ static bool translator_ld(CPUArchState *env, DisasContextBase *db, host = db->host_addr[1]; } - memcpy(dest, host + (pc - base), len); + do_read: + /* + * Assume aligned reads should be atomic, if possible. + * We're not in a position to jump out with EXCP_ATOMIC. + */ + host += pc - base; + switch (len) { + case 2: + if (QEMU_IS_ALIGNED(pc, 2)) { + uint16_t t = qatomic_read((uint16_t *)host); + stw_he_p(dest, t); + return true; + } + break; + case 4: + if (QEMU_IS_ALIGNED(pc, 4)) { + uint32_t t = qatomic_read((uint32_t *)host); + stl_he_p(dest, t); + return true; + } + break; +#ifdef CONFIG_ATOMIC64 + case 8: + if (QEMU_IS_ALIGNED(pc, 8)) { + uint64_t t = qatomic_read__nocheck((uint64_t *)host); + stl_he_p(dest, t); + return true; + } + break; +#endif + } + /* Unaligned or partial read from the second page is not atomic. */ + memcpy(dest, host, len); return true; }