From patchwork Mon Jul 18 13:59:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 591460 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp3055852max; Mon, 18 Jul 2022 07:22:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uzQC1msnMvqroGq0mPKrwa8uKIg+NbCFZjYCrEl1xSudLMYfJ0HHLx2daqDN3bEgpCL7BY X-Received: by 2002:ac8:5f06:0:b0:31e:e2b8:67c3 with SMTP id x6-20020ac85f06000000b0031ee2b867c3mr9148486qta.620.1658154169220; Mon, 18 Jul 2022 07:22:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658154169; cv=none; d=google.com; s=arc-20160816; b=oJhtVu97n7Dz+HAPJ0C5NynVjkVz7vhb/Yz5NXipfT9e76ncQrCuMlcdWRn0LLZoHG yzTyrOq+1bVrdkZoa4A8UBYnAR47bHB9/tzjylGMrIdmN5YjQVC+IMKB9EbnP8Dbs3oP KnDjZAMMC0mgovnuJKLkqC/nxGmQLZ16FOWSOhWHJaeqDJ5WhSwmxlDBnvJh2PGkZNm1 XSGt2gMOsD+kad3vFWKi5J5D2nhL0Iv/Vmq4le351nHmafmoo19YACPtEQfGtPRQRnQf vkQAYwoOHHX2O7v0t1yhBrRx0mlFCAOolxL5B1VzAY0ySXR63fOJkxRZzBqcCL3ODYgE tvYA== 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:to:from :dkim-signature; bh=oX0cz/UuX4deysfpkWLa72UX1jaFnIUFPBqr5lkXZCA=; b=S181jC/qrjBMjjcYrx+YWe67PHju5qvancsSBeIboXHFWkDjWQfDM+l2obwwQ5z1T6 87/YL1fXNhSE3hTMbiiZwO70JcTNR+8Dl+/cd/0jwrMP4hpoTgun71u6edI/S8hXXRAX a7gGUAqbIcah5eg8HqrvCPOZKxFG6svvg4cehb/kvBxBpX/j2EbHOWdhgK4mYMxeQss5 M+PrTjm8qMuDgj3Pn5cB0Xi8ns+FPh+KeQvRwt7lGbheYKvxzZ3JHT6hnUtLmW5amvgE OBOiJes2I/22OEyr16OjUCc4gxG3DKpIAgMA+DOiEy9ADTuHClZd7b/shUZdu0h9e9Or 5+Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GyY+vccb; 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 l125-20020a378983000000b006a6e5976423si5827496qkd.102.2022.07.18.07.22.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 18 Jul 2022 07:22:49 -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=GyY+vccb; 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]:51734 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oDRe4-0003cg-Pc for patch@linaro.org; Mon, 18 Jul 2022 10:22:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51658) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oDRHW-00026U-A3 for qemu-devel@nongnu.org; Mon, 18 Jul 2022 09:59:33 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]:36623) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oDRHU-0003AA-Cv for qemu-devel@nongnu.org; Mon, 18 Jul 2022 09:59:29 -0400 Received: by mail-wm1-x333.google.com with SMTP id p26-20020a1c545a000000b003a2fb7c1274so5282746wmi.1 for ; Mon, 18 Jul 2022 06:59:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=oX0cz/UuX4deysfpkWLa72UX1jaFnIUFPBqr5lkXZCA=; b=GyY+vccb5hxLsP7HyMVCGmdSxyX/tPTRKGMEBVpPwdknpykBiXvnenkFOmOlxnQTZS 8L5aWIDFJqMsYGxg8gNuk5equrCYbIxD7J3VWVh/b7tZs3HwSSCSzntageJsPIo1+OC+ w5ZMSfd1o5YRfmSA88onxXOWQZbt/AENRrwlYDw9ThAMLR8geaGc/b7aR5zs1AMo6iil V/STIlRxwGdNnIWWqZ/RikncIvLa5NqJpwgpJa89Pzpc1z8TwSxLU+w642adsWOrvZqU 2iktkl6koSkWf2iHHkVKp0WrkedPkm5Pcvleam3xw8Gs3hkXqU0FkB8tQm5hm6C5V17h W4NA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oX0cz/UuX4deysfpkWLa72UX1jaFnIUFPBqr5lkXZCA=; b=nUcLBgbiNTNgg0lD7YQdP4HF84tJTLwBxASgY0NtFMEFiDV6aJRxVFT0BLmdfEz3FY MKdDj3Tibr861DqDP6hVWi7T7qMb8DHrcwPTWk4J9814s+O8GTK+jCAl82GYs8Odm+K8 BTLfrO647xEQy5F3unL1pFbn2CPpw+DhdxU/3Wb+nLCfQSXq1fsPYSj6f62T5eoceNqW FWECzYdBZzEEA+0sJnnKrSG5T4jfcqApaEBB2iT+NITPUq54IDL85XQqwRCdGLf6l5TJ Tfjo18pkH8pIezeSfbU1U+68snoDi+YoCS9IU1wwct/BLZfW04cHS4x4gen6VJy72XEC j+mA== X-Gm-Message-State: AJIora9Nga0YCXVivc3sNgqUt9o/BPNQxojXqxwDy0uXJ1n/dB5mujSH 8QIDOwUJjBjmCs30ckqFP9G98C+t6NHLCw== X-Received: by 2002:a05:600c:3b29:b0:3a3:1fa6:768 with SMTP id m41-20020a05600c3b2900b003a31fa60768mr2004296wms.193.1658152766918; Mon, 18 Jul 2022 06:59:26 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id id15-20020a05600ca18f00b003a31f1edfa7sm1805798wmb.41.2022.07.18.06.59.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jul 2022 06:59:26 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 04/15] linux-user/aarch64: Do not clear PROT_MTE on mprotect Date: Mon, 18 Jul 2022 14:59:09 +0100 Message-Id: <20220718135920.13667-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220718135920.13667-1-peter.maydell@linaro.org> References: <20220718135920.13667-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x333.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, T_SCC_BODY_TEXT_LINE=-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" From: Richard Henderson The documentation for PROT_MTE says that it cannot be cleared by mprotect. Further, the implementation of the VM_ARCH_CLEAR bit, contains PROT_BTI confiming that bit should be cleared. Introduce PAGE_TARGET_STICKY to allow target/arch/cpu.h to control which bits may be reset during page_set_flags. This is sort of the opposite of VM_ARCH_CLEAR, but works better with qemu's PAGE_* bits that are separate from PROT_* bits. Reported-by: Vitaly Buka Signed-off-by: Richard Henderson Message-id: 20220711031420.17820-1-richard.henderson@linaro.org Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- target/arm/cpu.h | 7 +++++-- accel/tcg/translate-all.c | 13 +++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index 1e36a839ee4..6afcc882f2c 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3392,9 +3392,12 @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x) /* * AArch64 usage of the PAGE_TARGET_* bits for linux-user. + * Note that with the Linux kernel, PROT_MTE may not be cleared by mprotect + * mprotect but PROT_BTI may be cleared. C.f. the kernel's VM_ARCH_CLEAR. */ -#define PAGE_BTI PAGE_TARGET_1 -#define PAGE_MTE PAGE_TARGET_2 +#define PAGE_BTI PAGE_TARGET_1 +#define PAGE_MTE PAGE_TARGET_2 +#define PAGE_TARGET_STICKY PAGE_MTE #ifdef TARGET_TAGGED_ADDRESSES /** diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c index 8fd23a9d05f..ef62a199c7d 100644 --- a/accel/tcg/translate-all.c +++ b/accel/tcg/translate-all.c @@ -2256,6 +2256,15 @@ int page_get_flags(target_ulong address) return p->flags; } +/* + * Allow the target to decide if PAGE_TARGET_[12] may be reset. + * By default, they are not kept. + */ +#ifndef PAGE_TARGET_STICKY +#define PAGE_TARGET_STICKY 0 +#endif +#define PAGE_STICKY (PAGE_ANON | PAGE_TARGET_STICKY) + /* Modify the flags of a page and invalidate the code if necessary. The flag PAGE_WRITE_ORG is positioned automatically depending on PAGE_WRITE. The mmap_lock should already be held. */ @@ -2299,8 +2308,8 @@ void page_set_flags(target_ulong start, target_ulong end, int flags) p->target_data = NULL; p->flags = flags; } else { - /* Using mprotect on a page does not change MAP_ANON. */ - p->flags = (p->flags & PAGE_ANON) | flags; + /* Using mprotect on a page does not change sticky bits. */ + p->flags = (p->flags & PAGE_STICKY) | flags; } } }