Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4166996imm; Mon, 30 Jul 2018 09:45:17 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeu0GdcSJ0aSnkZYTQB/jfZ384X9jpAlL4DWUILdSAsTA4z4ez1qTLbv5JG8Gx5tJF5GbRf X-Received: by 2002:a62:4c0f:: with SMTP id z15-v6mr18425366pfa.110.1532969117195; Mon, 30 Jul 2018 09:45:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532969117; cv=none; d=google.com; s=arc-20160816; b=h2w3+2Yu2lnJZ/FH36j3DSYE4tgpUx00bnCkM8Xxo5Advw8l1mtv6lewyzW8ds/pcd jNZzh3m5FNL9YNt+B8iYsmMyRTlosYnSowfophUqp1RsU825uqMBQjmennV9Dg/vQHvH ukY0TAaNpszzLOV7WrHfjo2GiHlSulFAGjG9yIb06W+TdDXUKEuvFmX+Gl5uod3axtRb 7bWu/6AAX7plZU0a2H9ElTAgh52EM942RarsgFTe1eKvKkMqJ2Mf4t24zNAhJVZeW7gc dy+FfAVF7E/OOzvszHnxtf+NAiZo6R1SpQHSjIAuHU99NR01r84WqyCItowvSpvVx9Kj YzrA== 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:references:cc:to:subject:from:arc-authentication-results; bh=TNuhDAZ5L3j+8+ISZ6BZwKjvEHpphi0p46oBkH5OW9k=; b=ckR9ZrrvWrlRPNDx6L4ipZaT54b4caXf6BoAfCbN7YB3jANmM/eyqkdq8vmquwyaHo TIVpIu2UFRaOZhrBOVgCQUaM5euy+snpvyYxbGGEZ1rcG5MtkUK+eWGC4RAMjZhFLKla oh5wWX4wdk+3QcfvZNlmXgBPAW51o1d0ArfgwMTJ0FlZL7N5ebC59QQ89nSo+34gTpYP RlJHii/aeMLsyriU9BdzuOasxoRuaX7wvSCbaT+cqO88O+DX485bUR2ySNHtPJ4q2i2e VINqhRk2bIzhmGg7WK08gPAuE2ZGkD0yK6E3H5RM04cgtkr7hUk1ZTw4biiYsdgHTLiJ 7iBA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s64-v6si11894696pfg.175.2018.07.30.09.45.02; Mon, 30 Jul 2018 09:45:17 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732079AbeG3STU (ORCPT + 99 others); Mon, 30 Jul 2018 14:19:20 -0400 Received: from smtp20.cstnet.cn ([159.226.251.20]:51299 "EHLO cstnet.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726820AbeG3STU (ORCPT ); Mon, 30 Jul 2018 14:19:20 -0400 Received: from [192.168.1.7] (unknown [110.184.155.251]) by APP-10 (Coremail) with SMTP id tACowAD3_8_6P19bTuzwEQ--.34045S2; Tue, 31 Jul 2018 00:42:36 +0800 (CST) From: Pu Wen Subject: Re: [PATCH v2 01/17] x86/cpu: create Dhyana init file and register new cpu_dev to system To: Paolo Bonzini , tglx , bp , "thomas.lendacky" , mingo , hpa , peterz , "tony.luck" , rkrcmar , "boris.ostrovsky" , jgross , rjw , lenb , "viresh.kumar" , mchehab , trenn , shuah , x86 Cc: linux-kernel , linux-arch , kvm References: <1532352037-7151-1-git-send-email-puwen@hygon.cn> <1532352037-7151-2-git-send-email-puwen@hygon.cn> <201807290021145963620@hygon.cn> Message-ID: Date: Tue, 31 Jul 2018 00:42:37 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-CM-TRANSID: tACowAD3_8_6P19bTuzwEQ--.34045S2 X-Coremail-Antispam: 1UD129KBjvJXoWxur4UJw4rXr18XF45ZryUtrb_yoWrGr1fpF W5JFWUJw1vq3WfC34vyrW8WryFvFnxtw4UX3s8KFn7AFnxua45W39ayr4S9a4UCr1v9w17 t3y7XF4DWw4qva7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUvKb7Iv0xC_Kw4lb4IE77IF4wAFF20E14v26ryj6rWUM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVWUJVW8JwA2z4x0Y4vEx4 A2jsIEc7CjxVAFwI0_Gr0_Gr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI 64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8Jw Am72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41lFIxGxcIEc7CjxVA2Y2ka0xkIwI1l c7I2V7IY0VAS07AlzVAYIcxG8wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJV W8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF 1VAFwI0_GFv_WrylIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6x IIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6rWUJVWrZr1UMIIF 0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxh VjvjDU0xZFpf9x07b5sjbUUUUU= X-Originating-IP: [110.184.155.251] X-CM-SenderInfo: psxzv046klw03qof0z/ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018-07-29 07:42, Paolo Bonzini wrote: >If the maintainers are okay with X86_FEATURE_HYGON that's certainly >fine, however I think you can improve the consistency of the patches in >a few ways. Thanks for your suggestion. To improve code consistency , will rework the patches. > >Lack of SME/SEV is not an issue, since there are AMD Zen chips without >SME/SEV too, but potential incompatibility with future AMD fam18h chips >is important. Therefore, code like this one in amd_uncore_init > > >- if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD) >+ if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD && >+ boot_cpu_data.x86_vendor != X86_VENDOR_HYGON) > return -ENODEV; > > if (!boot_cpu_has(X86_FEATURE_TOPOEXT)) > return -ENODEV; > >- if (boot_cpu_data.x86 == 0x17) { >+ if (boot_cpu_data.x86 == 0x17 || boot_cpu_data.x86 == 0x18) { > >should check explicitly for Hygon before checking for family 18h. The >same applies to the edac patch that I've just sent an answer to. For the family number, As a JV company, to keep the consistency usage of CPU family convention, Hygon will negotiate with AMD to make sure the CPU family numbers both company used will not overlap. So as Hygon will use the family 18h for Dhyana, AMD will skip the family 18h and directly use family 19h for its new product. Based on this assumption, this patch set direct check the family number for 18h to see if it is Hygon processor to create a minimal patch set. For the consistency, will modify the codes as follows: - if (boot_cpu_data.x86 == 0x17) { + if (boot_cpu_data.x86 == 0x17 || + (boot_cpu_data.x86_vendor == X86_VENDOR_HYGON && + boot_cpu_data.x86 == 0x18)) { > >On the other hand, in many cases the AMD code is testing something like >"AMD && family >= 0x0f". In this case you have a mix of: > >- duplicate code for HYGON, such as modern_apic or mce_is_correctable > >- change the condition to (AMD || HYGON) && family >= 0x0f, such as >k8_check_syscfg_dram_mod_en and amd_special_default_mtrr > >- change the condition to (AMD && family >= 0x0f) || (HYGON && family >= >0x18), such as smp_quirk_init_udelay > >I couldn't find any case where you used (AMD && family >= 0x0f) || >HYGON, but I think it would be clearer in most cases than all the above >three alternatives. Your suggestion is correct, will try to make the code more consistent and update the next patch set to use (AMD && family >= 0x0f) || HYGON. > >In general, I would duplicate code if and only if the AMD code is a maze >of if/elseif/elseif. In particular, code like this > > case X86_VENDOR_AMD: > if (msr >= MSR_F15H_PERF_CTL) > return (msr - MSR_F15H_PERF_CTL) >> 1; > return msr - MSR_K7_EVNTSEL0; >+ case X86_VENDOR_HYGON: >+ if (msr >= MSR_F15H_PERF_CTL) >+ return (msr - MSR_F15H_PERF_CTL) >> 1; >+ return msr - MSR_K7_EVNTSEL0; > >or this > > case X86_VENDOR_AMD: > rdmsr_on_cpu(cpu, MSR_K7_HWCR, &lo, &hi); > msr = lo | ((u64)hi << 32); > return !(msr & MSR_K7_HWCR_CPB_DIS); >+ case X86_VENDOR_HYGON: >+ rdmsr_on_cpu(cpu, MSR_K7_HWCR, &lo, &hi); >+ msr = lo | ((u64)hi << 32); >+ return !(msr & MSR_K7_HWCR_CPB_DIS); > >looks a bit silly, and you already have several cases when you are not >introducing duplication (e.g. __mcheck_cpu_init_early). On the other >hand, code like xen_pmu_arch_init can be very simple for Hygon and so it >may be useful to have a separate branch. Thanks for the suggestion, will change this by directly reusing condition check if reused codes are direct: + case X86_VENDOR_HYGON: case X86_VENDOR_AMD: if (msr >= MSR_F15H_PERF_CTR) return (msr - MSR_F15H_PERF_CTR) >> 1; return msr - MSR_K7_PERFCTR0; Also will branch codes for Hygon in case of complicated checking condition such as in xen_pmu_arch_init(). Thanks, Pu Wen