From patchwork Thu Jan 28 22:41:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 372644 Delivered-To: patch@linaro.org Received: by 2002:a02:a60d:0:0:0:0:0 with SMTP id c13csp1674507jam; Thu, 28 Jan 2021 15:04:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJyaR75H6kbwtRjL46F5gJpJOaiugntlcSCOtDXX23KHkuhfupjd3rDRQGlUyE+QxWO3un0q X-Received: by 2002:a25:34c3:: with SMTP id b186mr3005569yba.325.1611875057405; Thu, 28 Jan 2021 15:04:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611875057; cv=none; d=google.com; s=arc-20160816; b=uFfvxbMBwQN3AqOL75sO7lSM3Fxxd4cz+qZ+DfrQ489POUCMwm6wwr+lTLTK2ypd3W yOJLurPcgC5DAuayH87UA9AxQe31hz7tO6d/v+nm5WuDBJpfOW1zSzxuEY6TRBoK54g9 CttH1GV+PtTK+L8F3t5AV71vOKv0riUG7ClM9oXLBfUlDeb8ki/mOZSMAUpekD9kpI74 Iq5dkP0ZFjR/+qP3NIPMg4LQvpUqGEOtUjVzzFInT0mLLtBZN3+C2R+h4UZdhxU4uAf6 +9KfzDyfps/dSsrP+KEZH1xs1C3uQTDDLMdKD3kVYj+Vmgh7jhX5S8xK3RfhqMyKnX65 kwJg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc: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:to:from :dkim-signature; bh=X+LaZKuwwsvEvbJ+r5ztAOZO016eLRKSU8aYWIJf1AQ=; b=dMD7U+pYWT2cWZuCt7+aJFJHIe1inENDamRM4zg+MaEFgcirjp4HnEa4O9hVVcRZ1Y csdlVjEVN1YQ9ynb2DvDTWuCOGkPzXcT3J2vZOV3yYpiO+14poK6Jop3Fu8TmGhEQMeF MlrtbEN/VwXAuBBVqdHtR0Ak88mQCTa41v9B/vL6Pu8Yu7PCp6Dg9QM2JWgQwcwbNQ7x XPiMOaQmEhQ03fbNhbY5/Md95AlX5YpRtcqst+MTa1OgfQHM43PwoprZElLhEImbeFNb lRDhKivkWISNI288M8yqBpVeulInQTcjzFsmxlszxcn3h85xbJpfV7qCsSX77qarfTP2 o0Kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=FLojX3ix; 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=fail (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 d24si8562367ybe.234.2021.01.28.15.04.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Jan 2021 15:04:17 -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=fail header.i=@linaro.org header.s=google header.b=FLojX3ix; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:41182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5GKm-0003KD-TO for patch@linaro.org; Thu, 28 Jan 2021 18:04:16 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33200) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5FzU-0005aY-7e for qemu-devel@nongnu.org; Thu, 28 Jan 2021 17:42:18 -0500 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:55837) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l5FzI-00089J-FY for qemu-devel@nongnu.org; Thu, 28 Jan 2021 17:42:14 -0500 Received: by mail-pj1-x1031.google.com with SMTP id s24so4718204pjp.5 for ; Thu, 28 Jan 2021 14:42:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X+LaZKuwwsvEvbJ+r5ztAOZO016eLRKSU8aYWIJf1AQ=; b=FLojX3ixA2yr6qJk8jYuO88bLmrIyoPpSgF02ee9VcqomnUs/FTBOJA0xeHzhF1gSK GlhwJZQ5QwBbfCE4UH5m22DPj84x47SVcdZGQDfskbT8Y09V/ZIts/pGOEd/E3sTQjxk NHa8aFWn8obcD+G2ApgvQL8CImzytrk47EFVdtt4zvVJMK4B6z2CU60/SjhTF2ANHiOv 0bchzib+5SCXPv1jvkOdS9HIBM5XvntEcmrWdrzQxFiS3B+yL0B6hdRmBMItm7Okk/97 PktnWWqEe8wnn1T0kNOwG1rF5LrQgBtw3gqH2ETkCRDPUh7LE40ihOd6Glxs1D/MlDRI 0VGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X+LaZKuwwsvEvbJ+r5ztAOZO016eLRKSU8aYWIJf1AQ=; b=rb7/R81AVwMCw/dDG/n+qiyAnhbtrQJymliBLsHqSCtGkF3deESsS+/M77OYpD1HQi NPJ/laUSZMKHh1ETy879ZNvhb/pFBTijRiuV5fmULcYmM3GKFyQAXkVhMzNPFLJgNxNg bJNHy9MZuWDur2bidwLivMB5CxwMLZMbSwcpKKewkkwg8hI+4FcsZ3b7Rv/JihRXuTHl dTm/sJvWS6GXHyTTkCPtnTgJdR+fHro6AojXpXf+hToSaJZE0710teUAfGcq8bh2qDhB Phad2l9slM5dQwkYurpO90q4SR3RiCoQFYVNlOT9ShtTyFjgjweDZoXYl7Fhat1QK8Jk klHQ== X-Gm-Message-State: AOAM532kJOFFn/Cs3oGjRmfDwXwjsbOLxfp/a5FphqYoNBVS5nZQzol7 lMjJixABBAY4NyejdvhA5HMGPyT+1a679nUj X-Received: by 2002:a17:90a:17c8:: with SMTP id q66mr1515883pja.167.1611873722704; Thu, 28 Jan 2021 14:42:02 -0800 (PST) Received: from localhost.localdomain (cpe-66-27-222-29.hawaii.res.rr.com. [66.27.222.29]) by smtp.gmail.com with ESMTPSA id m10sm6042358pjs.25.2021.01.28.14.42.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Jan 2021 14:42:02 -0800 (PST) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v4 11/23] exec: Add support for TARGET_TAGGED_ADDRESSES Date: Thu, 28 Jan 2021 12:41:29 -1000 Message-Id: <20210128224141.638790-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210128224141.638790-1-richard.henderson@linaro.org> References: <20210128224141.638790-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.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=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, qemu-arm@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The AArch64 Linux ABI has always enabled TBI, but has historically required that pointer tags be removed before a syscall. This has changed in the lead-up to ARMv8.5-MTE, in a way that affects the ABI generically and not specifically to MTE. This patch allows the target to indicate that (1) there are tags and (2) whether or not they should be taken into account at the syscall level. Adjust g2h, guest_addr_valid, and guest_range_valid to ignore pointer tags, similar to how TIF_TAGGED_ADDR alters __range_ok in the arm64 kernel source. The prctl syscall is not not yet updated, so this change by itself has no visible effect. Signed-off-by: Richard Henderson --- include/exec/cpu_ldst.h | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) -- 2.25.1 diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h index e62f4fba00..1df9b93e59 100644 --- a/include/exec/cpu_ldst.h +++ b/include/exec/cpu_ldst.h @@ -69,17 +69,31 @@ typedef uint64_t abi_ptr; #define TARGET_ABI_FMT_ptr "%"PRIx64 #endif +static inline abi_ptr untagged_addr(abi_ptr x) +{ +#ifdef TARGET_TAGGED_ADDRESSES + if (current_cpu) { + return cpu_untagged_addr(current_cpu, x); + } +#endif + return x; +} + /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ -#define g2h(x) ((void *)((uintptr_t)(abi_ptr)(x) + guest_base)) +static inline void *g2h(abi_ulong x) +{ + return (void *)((uintptr_t)untagged_addr(x) + guest_base); +} static inline bool guest_addr_valid(abi_ulong x) { - return x <= GUEST_ADDR_MAX; + return untagged_addr(x) <= GUEST_ADDR_MAX; } static inline bool guest_range_valid(abi_ulong start, abi_ulong len) { - return len - 1 <= GUEST_ADDR_MAX && start <= GUEST_ADDR_MAX - len + 1; + return len - 1 <= GUEST_ADDR_MAX && + untagged_addr(start) <= GUEST_ADDR_MAX - len + 1; } #define h2g_valid(x) \