Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp3602918ybc; Thu, 21 Nov 2019 10:44:45 -0800 (PST) X-Google-Smtp-Source: APXvYqzb2LX7If3COAaaas9/g+S1JePJGqj9LA+oqX6+P8ugBrmiVX1M/yWAVEIppaYcG1odaNnk X-Received: by 2002:a17:906:f91:: with SMTP id q17mr15773374ejj.302.1574361885666; Thu, 21 Nov 2019 10:44:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574361885; cv=none; d=google.com; s=arc-20160816; b=VHONs5/yr0CdsowVJFjboz/0CaEal5s392Kx+AgTObeg1IsW3pOj53asX+9+RsQs3K 1AjEI+jrFYhDyaJjQUjsKBMojHOv6lqvr1L2mAqmYnSvYE+NqzkYLe27dA5VD10fg8Yb wJjjTB2uOYF+/zazoGUk4EbL/TD5afXiCKjaO/qmRXo/wS2ZGVLU5Ak3tYyK6m+ca2my o/b2iMNSXBOYNcHb/2aXJOAgrUjVgBlmTIjQ7jvDRIi/+A3IiOpKFSfbevdoOF2MEZYs WjuubQpY7+ImJ8pV7YM0Y4hzaLkPBsGyELBdb//lHo1zb8G6T0+D7FbVMxcfkdoGd0Yh R6Uw== 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; bh=VhcDKO+y1fd8LoQRo0cmVUxG7fhxSbFYIDSmLNYwgfE=; b=LUt/0Lj1Ij2NbL0sM+NpdGQ4ttCuJHdFHb6x4cAjdEYcMnvhbROaax6ViqUw7QtqS0 hAvaYgg753IebGQg5flXckWxJ76ao+eO/DcYYHV7m3lNIVeIz3aQrKQMhX7Y1SvxBStJ FjjPQF2QqaLu1kIsvv7ELMLWrfqpG26eYGXVssRnfBiVtSlUMpTHgApZKlzttUhJGtZA jsp+2Erm0TNoioLOdPiPjZjLneDWfeHuRUKeMr++44tIKLrYX5tg4WsEdeqOtXL+M9tE 7xyVhr3lNsnuM98o5wr8QJN//fheMiFXlWckh1fl/Y8aifohu56GQagh/LAdPebQw+df hMoA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t21si2330002ejr.391.2019.11.21.10.44.22; Thu, 21 Nov 2019 10:44:45 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726689AbfKUSkx (ORCPT + 99 others); Thu, 21 Nov 2019 13:40:53 -0500 Received: from mga06.intel.com ([134.134.136.31]:4638 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726379AbfKUSkx (ORCPT ); Thu, 21 Nov 2019 13:40:53 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Nov 2019 10:40:52 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,226,1571727600"; d="scan'208";a="216191810" Received: from romley-ivt3.sc.intel.com ([172.25.110.60]) by fmsmga001.fm.intel.com with ESMTP; 21 Nov 2019 10:40:52 -0800 Date: Thu, 21 Nov 2019 10:53:03 -0800 From: Fenghua Yu To: Andy Lutomirski Cc: David Laight , Ingo Molnar , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , H Peter Anvin , Tony Luck , Ashok Raj , Ravi V Shankar , linux-kernel , x86 Subject: Re: [PATCH v10 6/6] x86/split_lock: Enable split lock detection by kernel parameter Message-ID: <20191121185303.GB199273@romley-ivt3.sc.intel.com> References: <1574297603-198156-1-git-send-email-fenghua.yu@intel.com> <1574297603-198156-7-git-send-email-fenghua.yu@intel.com> <20191121060444.GA55272@gmail.com> <20191121130153.GS4097@hirez.programming.kicks-ass.net> <20191121171214.GD12042@gmail.com> <3481175cbe14457a947f934343946d52@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 21, 2019 at 09:51:03AM -0800, Andy Lutomirski wrote: > On Thu, Nov 21, 2019 at 9:43 AM David Laight wrote: > > > > From: Ingo Molnar > > > Sent: 21 November 2019 17:12 > > > * Peter Zijlstra wrote: > > ... > > > > This feature MUST be default enabled, otherwise everything will > > > > be/remain broken and we'll end up in the situation where you can't use > > > > it even if you wanted to. > > > > > > Agreed. > > > > Before it can be enabled by default someone needs to go through the > > kernel and fix all the code that abuses the 'bit' functions by using them > > on int[] instead of long[]. > > > > I've only seen one fix go through for one use case of one piece of code > > that repeatedly uses potentially misaligned int[] arrays for bitmasks. > > > > Can we really not just change the lock asm to use 32-bit accesses for > set_bit(), etc? Sure, it will fail if the bit index is greater than > 2^32, but that seems nuts. > > (Why the *hell* do the bitops use long anyway? They're *bit masks* > for crying out loud. As in, users generally want to operate on fixed > numbers of bits.) We are working on a separate patch set to fix all split lock issues in atomic bitops. Per Peter Anvin and Tony Luck suggestions: 1. Still keep the byte optimization if nr is constant. No split lock. 2. If type of *addr is unsigned long, do quadword atomic instruction on addr. No split lock. 3. If type of *addr is unsigned int, do word atomic instruction on addr. No split lock. 4. Otherwise, re-calculate addr to point the 32-bit address which contains the bit and operate on the bit. No split lock. Only small percentage of atomic bitops calls are in case 4 (e.g. 3% for set_bit()) which need a few extra instructions to re-calculate address but can avoid big split lock overhead. To get real type of *addr instead of type cast type "unsigned long", the atomic bitops APIs are changed to macros from functions. This change need to touch all architectures. Thanks. -Fenghua