Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1155833pxb; Fri, 6 Nov 2020 02:24:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJy1MPnjzeNgAvPi61uwYXIP0kurutNSwFgLSLGRqmFJdxsF9Ub36XZZAldcAQEkxKV1zgsE X-Received: by 2002:aa7:c7d9:: with SMTP id o25mr1318478eds.318.1604658244302; Fri, 06 Nov 2020 02:24:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604658244; cv=none; d=google.com; s=arc-20160816; b=cR/DNVzAjzV1FDtLdmxsJFRt80JffmmydRxC4bDV35Z7NmeNln5iz+StAuODNOI0Yx RQWcI/7wdpD7x9L6vSRRyuqqN1S7iqGpWgIqTwjwR3HqBn1NBsLRFeuzF0YLgh42ytf4 +f4Wmv6qBCFyZbzWvbomOsEyU+vVZllgHTw/cG81kjMYvM7rzYCWxJXpWlhLWb/L2cQk 9UWvCfRCirFe+YndK560q9QjU2U6+K7j0JJf1iz5myHcNfrHmlhn7Ly8qbBv+mo/wbZj La3gyjJda13eZOIdOS0+/kRno81NOxhmER2jFIIMlQVteB8M88WIsSgXp+RPFho4THQd +CQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=5QBJe5lX3IDD/Nb41CDBzkfjHyizFuCqEuWd5FfCo5w=; b=cQzQg308xIEvBgo77ODJbg0px9IS9/rpNGHf63PYDdi9c/P5RG8h7uJZf+zFFjq/so aLdMUDF356CAdTZ0op5sBNmUwp+vvoXi15U7JdIMWwLVOuT80rug1FhkVa4vVb0jSZxD ZsP2ktcQmcQLjsydZR2nJ5E6GQbTEZL6LLEUAH3Gyncve2p1PR0siLMk9QwfXAF030Pt jtyOATwP3jXCy2ckm0U3b/J94/0nFtK5OWag+1FZ1vFVuqbe0E0xFK3mLwv5LxwxnprJ i6LRug5WXOpvpvUGO0I6IV+hRaItYZZF1Of8FNB/j6RjP/panPKsYEtMLemPmgtQg4VD /DLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iEoLJtq7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bq23si496403ejb.529.2020.11.06.02.23.41; Fri, 06 Nov 2020 02:24:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iEoLJtq7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727023AbgKFKTi (ORCPT + 99 others); Fri, 6 Nov 2020 05:19:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727014AbgKFKTi (ORCPT ); Fri, 6 Nov 2020 05:19:38 -0500 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EDA54C0613CF for ; Fri, 6 Nov 2020 02:19:37 -0800 (PST) Received: by mail-io1-xd41.google.com with SMTP id n12so931658ioc.2 for ; Fri, 06 Nov 2020 02:19:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=5QBJe5lX3IDD/Nb41CDBzkfjHyizFuCqEuWd5FfCo5w=; b=iEoLJtq7cjw5AUAmZWBPG2C1HwozPkret83awGEWM+zOt9HWYKNV9i+Q/bdl9RnmHC vu1GtiihpxGsh3XCS97k9PQb8wFx05tk7b5PIJJnLbPoF1OXfJE34vVnQQII+0QI+t/s QMvPEl2ZJeiLErc9y+HDMUwZxc02WQ/5jinIcw+ZaH1vk2goAQXKV6gEWEvHeSquwGBl PcEMQ1zVJCRFnvIQlu07tJ5Ui+uULjtzj37mS26QnOZlD8nUe0jImjNLbLBXcgTGPFy9 YwPFZ7bk2uqBlLzwDWbaznd4UDzh46EroOLDoIe5aMGRBfLfPa2CsegDDo/hOs/WnbOJ Migw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=5QBJe5lX3IDD/Nb41CDBzkfjHyizFuCqEuWd5FfCo5w=; b=q/QLqym+FfSS/r6/34TJRC1MAIdPYGNwSJRKtxxylH/04egISSL5kDTqGXZilu50hC TU/l6TK5XY1ZKRdsxm0WAM72pFImQ1F5A8x6y2m1D2t+Zg7WK35g1dFJ2IkBwH8k4k3A PHO/a14gLRcwN7X15v3ASWWAcVEO5fIBSfxS5lCXWcpfcKQ17J1Xm2A8xBekUc3zViQT 9SIKT/Fw4qFMzcOTOsSIfayZlqmuDCV5XnmoCdMOlJnyDcJmeyIRsHwNI0L31j7hNvP2 0oSoWVt0nrXXHcHWk2mAH7/BEZHCbFbDLsCkKTC1pErMVSzc7HsDF+snL/MH9RJEOixm wXZQ== X-Gm-Message-State: AOAM533FrhDZWssz8UYZySH+1AMZWCx6pzMMFy7bZjoC+h+9ABixjHHj 56a2J9UZTKyneYS9ooatGlU= X-Received: by 2002:a02:1349:: with SMTP id 70mr1020628jaz.130.1604657977371; Fri, 06 Nov 2020 02:19:37 -0800 (PST) Received: from auth1-smtp.messagingengine.com (auth1-smtp.messagingengine.com. [66.111.4.227]) by smtp.gmail.com with ESMTPSA id w81sm803656ilk.38.2020.11.06.02.19.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 06 Nov 2020 02:19:36 -0800 (PST) Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailauth.nyi.internal (Postfix) with ESMTP id 1E4FB27C005A; Fri, 6 Nov 2020 05:19:36 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Fri, 06 Nov 2020 05:19:36 -0500 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedujedruddtledgudehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvffukfhfgggtuggjsehttdertddttddvnecuhfhrohhmpeeuohhquhhn ucfhvghnghcuoegsohhquhhnrdhfvghnghesghhmrghilhdrtghomheqnecuggftrfgrth htvghrnhepvdelieegudfggeevjefhjeevueevieetjeeikedvgfejfeduheefhffggedv geejnecukfhppedufedurddutdejrddugeejrdduvdeinecuvehluhhsthgvrhfuihiivg epudenucfrrghrrghmpehmrghilhhfrhhomhepsghoqhhunhdomhgvshhmthhprghuthhh phgvrhhsohhnrghlihhthidqieelvdeghedtieegqddujeejkeehheehvddqsghoqhhunh drfhgvnhhgpeepghhmrghilhdrtghomhesfhhigihmvgdrnhgrmhgv X-ME-Proxy: Received: from localhost (unknown [131.107.147.126]) by mail.messagingengine.com (Postfix) with ESMTPA id AC58C306005F; Fri, 6 Nov 2020 05:19:35 -0500 (EST) Date: Fri, 6 Nov 2020 18:19:32 +0800 From: Boqun Feng To: Marco Elver Cc: paulmck@kernel.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, kernel-team@fb.com, mingo@kernel.org, andreyknvl@google.com, glider@google.com, dvyukov@google.com, cai@lca.pw Subject: Re: [PATCH v2] kcsan: Fix encoding masks and regain address bit Message-ID: <20201106101932.GD3025@boqun-archlinux> References: <20201105220302.GA15733@paulmck-ThinkPad-P72> <20201105220324.15808-3-paulmck@kernel.org> <20201106093456.GB2851373@elver.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201106093456.GB2851373@elver.google.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 06, 2020 at 10:34:56AM +0100, Marco Elver wrote: > The watchpoint encoding masks for size and address were off-by-one bit > each, with the size mask using 1 unnecessary bit and the address mask > missing 1 bit. However, due to the way the size is shifted into the > encoded watchpoint, we were effectively wasting and never using the > extra bit. > > For example, on x86 with PAGE_SIZE==4K, we have 1 bit for the is-write > bit, 14 bits for the size bits, and then 49 bits left for the address. > Prior to this fix we would end up with this usage: > > [ write<1> | size<14> | wasted<1> | address<48> ] > > Fix it by subtracting 1 bit from the GENMASK() end and start ranges of > size and address respectively. The added static_assert()s verify that > the masks are as expected. With the fixed version, we get the expected > usage: > > [ write<1> | size<14> | address<49> ] > > Functionally no change is expected, since that extra address bit is > insignificant for enabled architectures. > > Signed-off-by: Marco Elver Acked-by: Boqun Feng Regards, Boqun > --- > v2: > * Use WATCHPOINT_ADDR_BITS to avoid duplicating "BITS_PER_LONG-1 - > WATCHPOINT_SIZE_BITS" per Boqun's suggestion. > --- > kernel/kcsan/encoding.h | 14 ++++++-------- > 1 file changed, 6 insertions(+), 8 deletions(-) > > diff --git a/kernel/kcsan/encoding.h b/kernel/kcsan/encoding.h > index 4f73db6d1407..7ee405524904 100644 > --- a/kernel/kcsan/encoding.h > +++ b/kernel/kcsan/encoding.h > @@ -37,14 +37,12 @@ > */ > #define WATCHPOINT_ADDR_BITS (BITS_PER_LONG-1 - WATCHPOINT_SIZE_BITS) > > -/* > - * Masks to set/retrieve the encoded data. > - */ > -#define WATCHPOINT_WRITE_MASK BIT(BITS_PER_LONG-1) > -#define WATCHPOINT_SIZE_MASK \ > - GENMASK(BITS_PER_LONG-2, BITS_PER_LONG-2 - WATCHPOINT_SIZE_BITS) > -#define WATCHPOINT_ADDR_MASK \ > - GENMASK(BITS_PER_LONG-3 - WATCHPOINT_SIZE_BITS, 0) > +/* Bitmasks for the encoded watchpoint access information. */ > +#define WATCHPOINT_WRITE_MASK BIT(BITS_PER_LONG-1) > +#define WATCHPOINT_SIZE_MASK GENMASK(BITS_PER_LONG-2, WATCHPOINT_ADDR_BITS) > +#define WATCHPOINT_ADDR_MASK GENMASK(WATCHPOINT_ADDR_BITS-1, 0) > +static_assert(WATCHPOINT_ADDR_MASK == (1UL << WATCHPOINT_ADDR_BITS) - 1); > +static_assert((WATCHPOINT_WRITE_MASK ^ WATCHPOINT_SIZE_MASK ^ WATCHPOINT_ADDR_MASK) == ~0UL); > > static inline bool check_encodable(unsigned long addr, size_t size) > { > -- > 2.29.2.222.g5d2a92d10f8-goog >