From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752354AbcHHShs (ORCPT ); Mon, 8 Aug 2016 14:37:48 -0400 Received: from mail.skyhub.de ([78.46.96.112]:43974 "EHLO mail.skyhub.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752232AbcHHShr (ORCPT ); Mon, 8 Aug 2016 14:37:47 -0400 Date: Mon, 8 Aug 2016 20:37:26 +0200 From: Borislav Petkov To: Linus Torvalds Cc: Ville =?utf-8?B?U3lyasOkbMOk?= , Linux Kernel Mailing List , the arch/x86 maintainers , Borislav Petkov , "H . Peter Anvin" , Andy Lutomirski , Brian Gerst , Denys Vlasenko , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Jiri Kosina Subject: Re: [PATCH] x86/hweight: Don't clobber %rdi Message-ID: <20160808183726.GA22641@nazgul.tnic> References: <1470677729-10561-1-git-send-email-ville.syrjala@linux.intel.com> <20160808180430.GE511@nazgul.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.6.0 (2016-04-01) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 08, 2016 at 11:21:20AM -0700, Linus Torvalds wrote: > ... > in arch/x86/events/intel/core.c, which then corrupts something related > to the event constraints, and then you get the oops in > x86_perf_event_update() later. Damn. And I thought that when I hold on to the C ABI and since %rdi is callee-clobbered, I can simply do "call __sw_hweight64" from within an asm() statement and it'll all be fine. Ok, so do you think it would work too if I stated that the input register gets clobbered: asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT) : "="REG_OUT (res) : REG_IN (w) : REG_IN); (untested of course). Because my primitive way of thinking would go like this: well, the input register is in the list of clobbers and gcc should take care of stashing it away if it is live across the hweight call. IOW, let gcc do the push/pop instead of us doing it explicitly. Or am I missing some aspect? > The compiler has absolutely nothing to do with this. It's all assembly > language and an inline asm. I meant I shouldn't do the compiler's job by coding __sw_hweightXX in asm. Even though arch/x86/lib/hweight.S is basically copied gcc asm output, more or less. But that got us rid of the special calling convention which was a win in itself. Thanks. -- Regards/Gruss, Boris. ECO tip #101: Trim your mails when you reply. --