Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp872079ybe; Fri, 13 Sep 2019 07:36:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqwEu5x7km3ZE1P0LQ8CIQEM0jPBXF1mDHhFlLNzM++2+s6J27d7cj9IjuZKlJtpUh6+eBkA X-Received: by 2002:aa7:d904:: with SMTP id a4mr3577976edr.41.1568385368239; Fri, 13 Sep 2019 07:36:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568385368; cv=none; d=google.com; s=arc-20160816; b=HbYKe6uX9FXuZ3rM1JRonJKW9uESrZgCKlZ2IbKvENfl9mAQI8JtT9KpMGQ5swGsVy KzzesUUcL18L1SPZDxXzj16ZWbiBAamKsE6NSVBNcTUNHOYnYHEr/zZqvq+fv26ZUHeH 8DzpcLoPagdAvNttjsepx1LfzwB7QCq6zViGej4MPUAPgHLK6YSfK1Kd7dmMLU9TBvPc KVWZPSkZXHCHikXESBEGopAbt/JIk3/KK+YgqhMsHkWwr43R/WHRHoYXrDak++yuSJ0V yngM++GdEhHrnRfIuEhF6PKjYESaIECHL3I/KC37quGwIMkkYBZz84hFGxYZUWA4hQRP NkVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=FEUAuFNSQvuR3RsMDZaXz3ghisFRlkD0kcIhhXnO+ck=; b=0akZclFleXSrHHhu6GMfcrcrDPpY3Jtr1NEJ3N4gnQbJ9f4tHdVnLVqSnCkxo1aJRd Rnt0b+b4UVKEFoe2ICxl9EvXeBqH+Ar7sA4x7J2WpuTFdF+iIJUPE0FY8PhaEwH4NwS1 +NwN92V5zdJEkWnwbkL2Kalk/ZtRZgDF8yuU38ADd+pKRmsDS2K3Mr9ap95Rbd30P/7l l5j3dbNr5NKhdQ/5kkB+6JZ9Qpj9v5UHe6wE6FXWuy7ge7LYHZu65WuWMzug2ckXgNgg XdrtG8WzZH2fyO1bhX7In9hEYlzotXROytAkqf8cMCCtNCDom9kDPbKH+k+gKb9sptXx ss1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b="eQO/NvmP"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a9si14725346edn.318.2019.09.13.07.35.45; Fri, 13 Sep 2019 07:36:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@alien8.de header.s=dkim header.b="eQO/NvmP"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alien8.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387822AbfIMKmj (ORCPT + 99 others); Fri, 13 Sep 2019 06:42:39 -0400 Received: from mail.skyhub.de ([5.9.137.197]:36026 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387512AbfIMKmi (ORCPT ); Fri, 13 Sep 2019 06:42:38 -0400 Received: from zn.tnic (p200300EC2F0DC5002486B65DCA157D7D.dip0.t-ipconnect.de [IPv6:2003:ec:2f0d:c500:2486:b65d:ca15:7d7d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.skyhub.de (SuperMail on ZX Spectrum 128k) with ESMTPSA id 864081EC03F6; Fri, 13 Sep 2019 12:42:37 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alien8.de; s=dkim; t=1568371357; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references; bh=FEUAuFNSQvuR3RsMDZaXz3ghisFRlkD0kcIhhXnO+ck=; b=eQO/NvmPRsgbqCkVgxDJkL4GAGLwYSoDvWhoSjR7MI0JpLM/lQCrFY+fodwwbDgDFnEWyw bGsO2U0Nq/uQMt8dFLsSvW6VzIW4sCyPx2as8f9PE6JwePHv69COCsaCzuLQTDDFpdatzI PVgL6AGZXmv63vTAeDNzUhiZOtAGcLY= Date: Fri, 13 Sep 2019 12:42:32 +0200 From: Borislav Petkov To: Rasmus Villemoes Cc: Linus Torvalds , x86-ml , Andy Lutomirski , Josh Poimboeuf , lkml Subject: Re: [RFC] Improve memset Message-ID: <20190913104232.GA4190@zn.tnic> References: <20190913072237.GA12381@zn.tnic> <9dc9f1e6-5d19-167c-793d-2f4a5ebee097@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <9dc9f1e6-5d19-167c-793d-2f4a5ebee097@rasmusvillemoes.dk> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 13, 2019 at 11:18:00AM +0200, Rasmus Villemoes wrote: > Something like > > if (__builtin_constant_p(c) && __builtin_constant_p(n) && n <= 32) > return __builtin_memset(dest, c, n); > > might be enough? Of course it would be sad if 32 was so high that this > turned into a memset() call, but there's -mmemset-strategy= if one wants > complete control. Though that's of course build-time, so can't consider > differences between cpu models. Yah, that seems to turn this: memset(&tr, 0, sizeof(tr)); tr.b = b; where sizeof(tr) < 32 into: # ./arch/x86/include/asm/string_64.h:29: return __builtin_memset(dest, c, n); movq $0, 16(%rsp) #, MEM[(void *)&tr + 8B] movq $0, 24(%rsp) #, MEM[(void *)&tr + 8B] # arch/x86/kernel/cpu/mce/amd.c:1070: tr.b = b; movq %rbx, 8(%rsp) # b, tr.b which is 2 u64 moves and the assignment of b at offset 8. Question is, where we should put the size cap? I'm thinking 32 or 64 bytes... Linus, got any suggestions? Or should we talk to Intel hw folks about it... -- Regards/Gruss, Boris. https://people.kernel.org/tglx/notes-about-netiquette