Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp675136rwl; Wed, 12 Apr 2023 02:24:03 -0700 (PDT) X-Google-Smtp-Source: AKy350bk5gAzU1wio1I7Jpm9fjs2TbhTKPsv9ufupAFErZGBedzUaFEwWhfySbDsljWMsmYle522 X-Received: by 2002:a05:6a20:465c:b0:db:3a56:bbd with SMTP id eb28-20020a056a20465c00b000db3a560bbdmr17405099pzb.2.1681291442906; Wed, 12 Apr 2023 02:24:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681291442; cv=none; d=google.com; s=arc-20160816; b=YeQ1K5ZAKND7sOsobPHe5VrQNsOZCrYGOGMaU39U16HEBP/LEQ+NRZkHN04dpeq6t2 e442Bk4J73wR29OFyBnCOCMIhk+Nc5RdIybY//iyeDEHwU5NR0SHLSdHolEi+yVZEG/L zdJdmfgwTozUJhoqCP4icXQThBIn0svZn8wJnh+3p6y6RBZRuhqotYJehaG79Nl0/N13 R7/Wg0rmCeUv4ryj2nFqg6ASZEb0TB6snkAD+/ADMcyb+re0oJWIj6dU/lreukPHvI/S jv0Rx78qfhzFYDsxBiR7NJ4nm4ZPIrUNorPBo+z23kJMlFSLmI+aWJ4ii90ju6WjxS6J FcGw== 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; bh=8cejxE8JtROdUH5S/bUEhrTa7h5CsiyhsOVkqdlwTn0=; b=gXanQ8hZUiGArhy9pX/duu42mape2Y9bxSCB4uS3v04w0UFmGawe15lzoswFtkA/mi fGBmSAgIZlZVRztb0nr68igp4wU5oAKqtPHRB3p2Rqpup9hNyKjOUJtC+yeu61pwIOlP VV0nz3dpJaSb+jmIoxc2Lwg/qVTbB2HeJjH28k68+Ro6OEkIx/7usbvs6YDjjtfRE4Ef d6tC5mYRWDbqNea7Kbq3DGmbEykaqS8njbsxptvNj61pdX6Vii/1OpwfeXxSJkESjnQH sOfrCDRfWU6NW+3/xYOHhN1SG8uvqF3fbI8xM1qD2uy64f1fOBMLwh8bGHtGcchp3p1a k5qQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 8-20020a630108000000b0051b2ba6c511si2015705pgb.568.2023.04.12.02.23.51; Wed, 12 Apr 2023 02:24:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229825AbjDLJCW (ORCPT + 99 others); Wed, 12 Apr 2023 05:02:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229506AbjDLJCU (ORCPT ); Wed, 12 Apr 2023 05:02:20 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 28452A9 for ; Wed, 12 Apr 2023 02:02:19 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 53BB5C14; Wed, 12 Apr 2023 02:03:03 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.21.3]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E7B153F587; Wed, 12 Apr 2023 02:02:17 -0700 (PDT) Date: Wed, 12 Apr 2023 10:02:15 +0100 From: Mark Rutland To: Heiko Carstens Cc: Kees Cook , Alexander Popov , Vasily Gorbik , linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] s390/stackleak: provide fast __stackleak_poison() implementation Message-ID: References: <20230405130841.1350565-1-hca@linux.ibm.com> <20230405130841.1350565-3-hca@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230405130841.1350565-3-hca@linux.ibm.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 05, 2023 at 03:08:41PM +0200, Heiko Carstens wrote: > Provide an s390 specific __stackleak_poison() implementation which is > faster than the generic variant. > > For the original implementation with an enforced 4kb stackframe for the > getpid() system call the system call overhead increases by a factor of 3 if > the stackleak feature is enabled. Using the s390 mvc based variant this is > reduced to an increase of 25% instead. > > This is within the expected area, since the mvc based implementation is > more or less a memset64() variant which comes with similar results. See > commit 0b77d6701cf8 ("s390: implement memset16, memset32 & memset64"). With that in mind, could we use memset64() directly (if we made it noninstr-safe)? Mark. > > Reviewed-by: Vasily Gorbik > Signed-off-by: Heiko Carstens > --- > arch/s390/include/asm/processor.h | 35 +++++++++++++++++++++++++++++++ > 1 file changed, 35 insertions(+) > > diff --git a/arch/s390/include/asm/processor.h b/arch/s390/include/asm/processor.h > index efffc28cbad8..dc17896a001a 100644 > --- a/arch/s390/include/asm/processor.h > +++ b/arch/s390/include/asm/processor.h > @@ -118,6 +118,41 @@ unsigned long vdso_size(void); > > #define HAVE_ARCH_PICK_MMAP_LAYOUT > > +#define __stackleak_poison __stackleak_poison > +static __always_inline void __stackleak_poison(unsigned long erase_low, > + unsigned long erase_high, > + unsigned long poison) > +{ > + unsigned long tmp, count; > + > + count = erase_high - erase_low; > + if (!count) > + return; > + asm volatile( > + " cghi %[count],8\n" > + " je 2f\n" > + " aghi %[count],-(8+1)\n" > + " srlg %[tmp],%[count],8\n" > + " ltgr %[tmp],%[tmp]\n" > + " jz 1f\n" > + "0: stg %[poison],0(%[addr])\n" > + " mvc 8(256-8,%[addr]),0(%[addr])\n" > + " la %[addr],256(%[addr])\n" > + " brctg %[tmp],0b\n" > + "1: stg %[poison],0(%[addr])\n" > + " larl %[tmp],3f\n" > + " ex %[count],0(%[tmp])\n" > + " j 4f\n" > + "2: stg %[poison],0(%[addr])\n" > + " j 4f\n" > + "3: mvc 8(1,%[addr]),0(%[addr])\n" > + "4:\n" > + : [addr] "+&a" (erase_low), [count] "+&d" (count), [tmp] "=&a" (tmp) > + : [poison] "d" (poison) > + : "memory", "cc" > + ); > +} > + > /* > * Thread structure > */ > -- > 2.37.2 >