From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 139D5C433E1 for ; Thu, 27 Aug 2020 11:11:52 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CA0F222CB3 for ; Thu, 27 Aug 2020 11:11:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="VDNzGjUS" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CA0F222CB3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=RCf5AiLXwjrrEJuly7LNXsaf46CicE3mFF5iP3hXZnQ=; b=VDNzGjUSfamnd/d7mWv6VcXKG hhBknEKGCjpchYlXctw9KlcRdq31htwFQW1RNlw0cM4p6iOLKHC2FnSe4QOvHcI3YdChellf6QJCM pVzvKvsYktYEr3oJ9wwsr9Z+7ZbDCvCX3hlCFdV76pcsfdQ1CvN3QE/cvCBxKCKTHfZH4G+Kq0dNN YKMyWrpAd3iZ0hNIK5Jg0r08reWDiVuYihHwp2i0Z3KYkJsUSh/deMLsG710qM0gmlIeMyVg6OKLy tqoxE1czsbpcqFhUiJWTrrUilLiKdaWvqQR/cCErDhXD58KKz7RfRjWZrPXrLrU+nF55AxoKsZC4k MWNAIjPyw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBFng-0003dZ-TW; Thu, 27 Aug 2020 11:10:36 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kBFne-0003cs-9K for linux-arm-kernel@lists.infradead.org; Thu, 27 Aug 2020 11:10:35 +0000 Received: from gaia (unknown [46.69.195.127]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 39DEE22BF3; Thu, 27 Aug 2020 11:10:31 +0000 (UTC) Date: Thu, 27 Aug 2020 12:10:28 +0100 From: Catalin Marinas To: Vincenzo Frascino Subject: Re: [PATCH 20/35] arm64: mte: Add in-kernel MTE helpers Message-ID: <20200827111027.GJ29264@gaia> References: <2cf260bdc20793419e32240d2a3e692b0adf1f80.1597425745.git.andreyknvl@google.com> <20200827093808.GB29264@gaia> <588f3812-c9d0-8dbe-fce2-1ea89f558bd2@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <588f3812-c9d0-8dbe-fce2-1ea89f558bd2@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200827_071034_422595_1AB36558 X-CRM114-Status: GOOD ( 27.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, Marco Elver , Elena Petrova , Andrey Konovalov , Kevin Brodsky , Will Deacon , Branislav Rankov , kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexander Potapenko , Evgenii Stepanov , Andrey Ryabinin , Andrew Morton , Dmitry Vyukov Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, Aug 27, 2020 at 11:31:56AM +0100, Vincenzo Frascino wrote: > On 8/27/20 10:38 AM, Catalin Marinas wrote: > > On Fri, Aug 14, 2020 at 07:27:02PM +0200, Andrey Konovalov wrote: > >> +void * __must_check mte_set_mem_tag_range(void *addr, size_t size, u8 tag) > >> +{ > >> + void *ptr = addr; > >> + > >> + if ((!system_supports_mte()) || (size == 0)) > >> + return addr; > >> + > >> + tag = 0xF0 | (tag & 0xF); > >> + ptr = (void *)__tag_set(ptr, tag); > >> + size = ALIGN(size, MTE_GRANULE_SIZE); > > > > I think aligning the size is dangerous. Can we instead turn it into a > > WARN_ON if not already aligned? At a quick look, the callers of > > kasan_{un,}poison_memory() already align the size. > > The size here is used only for tagging purposes and if we want to tag a > subgranule amount of memory we end up tagging the granule anyway. Why do you > think it can be dangerous? In principle, I don't like expanding the size unless you are an allocator. Since this code doesn't control the placement of the object it was given, a warn seems more appropriate. > >> +/* > >> + * Assign allocation tags for a region of memory based on the pointer tag > >> + * x0 - source pointer > >> + * x1 - size > >> + * > >> + * Note: size is expected to be MTE_GRANULE_SIZE aligned > >> + */ > >> +SYM_FUNC_START(mte_assign_mem_tag_range) > >> + /* if (src == NULL) return; */ > >> + cbz x0, 2f > >> + /* if (size == 0) return; */ > > > > You could skip the cbz here and just document that the size should be > > non-zero and aligned. The caller already takes care of this check. > > I would prefer to keep the check here, unless there is a valid reason, since > allocate(0) is a viable option hence tag(x, 0) should be as well. The caller > takes care of it in one place, today, but I do not know where the API will be > used in future. That's why I said just document it in the comment above the function. The check is also insufficient if the size is not aligned to an MTE granule, so it's not really consistent. This function should end with a subs followed by b.gt as cbnz will get stuck in a loop for unaligned size. -- Catalin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel