Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4925062ybv; Mon, 17 Feb 2020 08:32:54 -0800 (PST) X-Google-Smtp-Source: APXvYqyMliD2aAClnXrCseKOHVebzYdqqISqTjptHUih0ZiwDiWV50YJy72q+Do6juRUsu6hVHEw X-Received: by 2002:a9d:7593:: with SMTP id s19mr12122130otk.219.1581957174205; Mon, 17 Feb 2020 08:32:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581957174; cv=none; d=google.com; s=arc-20160816; b=FYc97CUJanKsGSI026SZOCj12Bh3D8AH55negWweupsrEnCENdkSz17J7HFpn1o3qz MhiLj8v/cFVdbWW52IIhpybm5GVKRZmHecR3SJ9zF9KBbgkqK2ETwD7rEY9xDm2BBJd7 LbGDqKaXShoNiNnl95QnFVDuNKauDBDDkV7oTESPE0MMM1OZ6YmU6bjMPv9ZKZ6Gx28X 5Xgv7f6noruSD/0hLtpDLRcILNUraVde+4NuobR4dwUcE3vxmFITShVTjWg1EaYAE3/8 IL8x4joMGXCrQXt2IiWx7qygUwallWcndtGSrE04fcpyOH8zZkH9EXzcRR+cTSScxuKY Fi/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=6DgjkXbrR+aTgzwFOwaNUb/pGw0eTRC9dHf2eJzgmD4=; b=mLQTm8deRiLO4OCtLxhc2z8z9WDdNedwN1fp+SgUcoHJpjHBgMiwayl5n3wLOukaof aQ3zJDauiYzVBY3eNQean0qwT49+wdWjMnXxjkZE9M6N3YPZhqRnSxzeMSlwpju1L3ue 4XlamkLzjnGLe4yuuQLx7UdCgyE/bSrKFWsYZTRNTzpIo9E9cKn9/0ymksXJl0Lgvyt+ 2O9YghjnmF/M1MRKn+tl7BxXxACvOj2RFZB5/RMG2V80PRzVbIMvD8BIPJ/BfrYgY9AO t0Z5W8xNo/7rtT/mvjrlLP9mmcZ8ER1p4Fnbvi3v0jGk8MDwR7bgTYqr8SeHv0DvVRaq NFXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MGmxuWOc; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h9si404414oti.155.2020.02.17.08.32.41; Mon, 17 Feb 2020 08:32:54 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MGmxuWOc; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729041AbgBQQcK (ORCPT + 99 others); Mon, 17 Feb 2020 11:32:10 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:32146 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728884AbgBQQcJ (ORCPT ); Mon, 17 Feb 2020 11:32:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581957127; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6DgjkXbrR+aTgzwFOwaNUb/pGw0eTRC9dHf2eJzgmD4=; b=MGmxuWOcsqMKJVPUrVb4LEV0S476PvQRPOMfpe4AY7XMauSURQgMeG1C/t9Dtyj2fBUdZg /eD791wU57UfPU4SUMKFGIInR5Ab+p7Cw49vBto/Aht7KQRNe9E5+beXwko6/Kw10mcwfQ I5bma4IzGEyg4G/0may3QRGTHqRuRfM= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-248-3lXvF2PbN4qGo6V5SohVJg-1; Mon, 17 Feb 2020 11:32:05 -0500 X-MC-Unique: 3lXvF2PbN4qGo6V5SohVJg-1 Received: by mail-wm1-f70.google.com with SMTP id f207so7211574wme.6 for ; Mon, 17 Feb 2020 08:32:05 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=6DgjkXbrR+aTgzwFOwaNUb/pGw0eTRC9dHf2eJzgmD4=; b=s8rDmwyNDABDgUC8+i9U5HgsraC1Pi8EAHNESUUoxJc3X+bJhb3vf8As1GMQbdNhqi 7jxjSdCwVez9Gg7af9AVnaUioIyd1C/cK4oOVqWUlQUv8VbpdUyH3c6s21x9EdjzqvWf V3Hn2gIG6bG0mCtEf52CkwA3RLE1Er0PY9Mmz7U4+BF63QqZ9jgLqtxRKKHipmigHc8P usU+KrZuizLxByAHL/+DkhDX/2/7Co11gv75ehMzHLDKzX1Gx1L89yaHJ2K4wjvjnKUL +9moqXElYfPIrmS5lL9cnUtCdEJCclyc41kjy0FtZfhV4RwjNlomxdTo55rwAz2KqB2A fcHw== X-Gm-Message-State: APjAAAWao2ZO6RgHviBg18Cqg/67yCOH4VBQzgSDa9z5yZqSfZw2cUhG 78wjrZ7LMrepUVA1SIfijl4IKPRYCkl7uG72eJgHd/dmKuCPQiRL3RbkNZnV6E1Epm/HIVjai0a 9P27xZtCzmmxXxhGpdiWyssYr X-Received: by 2002:adf:806c:: with SMTP id 99mr22067829wrk.328.1581957124418; Mon, 17 Feb 2020 08:32:04 -0800 (PST) X-Received: by 2002:adf:806c:: with SMTP id 99mr22067803wrk.328.1581957124159; Mon, 17 Feb 2020 08:32:04 -0800 (PST) Received: from ?IPv6:2001:b07:6468:f312:59c7:c3ee:2dec:d2b4? ([2001:b07:6468:f312:59c7:c3ee:2dec:d2b4]) by smtp.gmail.com with ESMTPSA id c141sm1087609wme.41.2020.02.17.08.32.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 17 Feb 2020 08:32:03 -0800 (PST) Subject: Re: [PATCH] kvm/emulate: fix a -Werror=cast-function-type To: Qian Cai , Jim Mattson Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Joerg Roedel , kvm list , LKML References: <1581695768-6123-1-git-send-email-cai@lca.pw> <20200214165923.GA20690@linux.intel.com> <1581700124.7365.70.camel@lca.pw> <1581707646.7365.72.camel@lca.pw> <28680b99-d043-ee02-dab3-b5ce8c2e625b@redhat.com> <1581950844.7365.82.camel@lca.pw> From: Paolo Bonzini Message-ID: <030ced86-5ef0-0a2e-7c66-dbfb1416b8b5@redhat.com> Date: Mon, 17 Feb 2020 17:32:02 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 MIME-Version: 1.0 In-Reply-To: <1581950844.7365.82.camel@lca.pw> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 17/02/20 15:47, Qian Cai wrote: > On Fri, 2020-02-14 at 20:33 +0100, Paolo Bonzini wrote: >> On 14/02/20 20:14, Qian Cai wrote: >>>> It seems misguided to define a local variable just to get an implicit >>>> cast from (void *) to (fastop_t). Sean's first suggestion gives you >>>> the same implicit cast without the local variable. The second >>>> suggestion makes both casts explicit. >>> >>> OK, I'll do a v2 using the first suggestion which looks simpler once it passed >>> compilations. >>> >> >> Another interesting possibility is to use an unnamed union of a >> (*execute) function pointer and a (*fastop) function pointer. >> > > This? Yes, perfect. Can you send it with Signed-off-by and all that? Thanks, Paolo > diff --git a/arch/x86/include/asm/kvm_emulate.h > b/arch/x86/include/asm/kvm_emulate.h > index 03946eb3e2b9..2a8f2bd2e5cf 100644 > --- a/arch/x86/include/asm/kvm_emulate.h > +++ b/arch/x86/include/asm/kvm_emulate.h > @@ -292,6 +292,14 @@ enum x86emul_mode { >  #define X86EMUL_SMM_MASK             (1 << 6) >  #define X86EMUL_SMM_INSIDE_NMI_MASK  (1 << 7) >   > +/* > + * fastop functions are declared as taking a never-defined fastop parameter, > + * so they can't be called from C directly. > + */ > +struct fastop; > + > +typedef void (*fastop_t)(struct fastop *); > + >  struct x86_emulate_ctxt { >   const struct x86_emulate_ops *ops; >   > @@ -324,7 +332,10 @@ struct x86_emulate_ctxt { >   struct operand src; >   struct operand src2; >   struct operand dst; > - int (*execute)(struct x86_emulate_ctxt *ctxt); > + union { > + int (*execute)(struct x86_emulate_ctxt *ctxt); > + fastop_t fop; > + }; >   int (*check_perm)(struct x86_emulate_ctxt *ctxt); >   /* >    * The following six fields are cleared together, > diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c > index ddbc61984227..dd19fb3539e0 100644 > --- a/arch/x86/kvm/emulate.c > +++ b/arch/x86/kvm/emulate.c > @@ -191,25 +191,6 @@ >  #define NR_FASTOP (ilog2(sizeof(ulong)) + 1) >  #define FASTOP_SIZE 8 >   > -/* > - * fastop functions have a special calling convention: > - * > - * dst:    rax        (in/out) > - * src:    rdx        (in/out) > - * src2:   rcx        (in) > - * flags:  rflags     (in/out) > - * ex:     rsi        (in:fastop pointer, out:zero if exception) > - * > - * Moreover, they are all exactly FASTOP_SIZE bytes long, so functions for > - * different operand sizes can be reached by calculation, rather than a jump > - * table (which would be bigger than the code). > - * > - * fastop functions are declared as taking a never-defined fastop parameter, > - * so they can't be called from C directly. > - */ > - > -struct fastop; > - >  struct opcode { >   u64 flags : 56; >   u64 intercept : 8; > @@ -311,8 +292,19 @@ static void invalidate_registers(struct x86_emulate_ctxt > *ctxt) >  #define ON64(x) >  #endif >   > -typedef void (*fastop_t)(struct fastop *); > - > +/* > + * fastop functions have a special calling convention: > + * > + * dst:    rax        (in/out) > + * src:    rdx        (in/out) > + * src2:   rcx        (in) > + * flags:  rflags     (in/out) > + * ex:     rsi        (in:fastop pointer, out:zero if exception) > + * > + * Moreover, they are all exactly FASTOP_SIZE bytes long, so functions for > + * different operand sizes can be reached by calculation, rather than a jump > + * table (which would be bigger than the code). > + */ >  static int fastop(struct x86_emulate_ctxt *ctxt, fastop_t fop); >   >  #define __FOP_FUNC(name) \ > @@ -5683,7 +5675,7 @@ int x86_emulate_insn(struct x86_emulate_ctxt *ctxt) >   >   if (ctxt->execute) { >   if (ctxt->d & Fastop) > - rc = fastop(ctxt, (fastop_t)ctxt->execute); > + rc = fastop(ctxt, ctxt->fop); >   else >   rc = ctxt->execute(ctxt); >   if (rc != X86EMUL_CONTINUE) >