From patchwork Wed Apr 21 14:56:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12216319 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F129C433B4 for ; Wed, 21 Apr 2021 14:56:15 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3E3BE613FA for ; Wed, 21 Apr 2021 14:56:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3E3BE613FA Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.114783.218794 (Exim 4.92) (envelope-from ) id 1lZEGs-0007qo-So; Wed, 21 Apr 2021 14:56:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 114783.218794; Wed, 21 Apr 2021 14:56:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZEGs-0007qh-Pc; Wed, 21 Apr 2021 14:56:06 +0000 Received: by outflank-mailman (input) for mailman id 114783; Wed, 21 Apr 2021 14:56:05 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZEGr-0007qX-K6 for xen-devel@lists.xenproject.org; Wed, 21 Apr 2021 14:56:05 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a8511cc5-5931-4b24-a74b-bace21e8a439; Wed, 21 Apr 2021 14:56:04 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id DB6ACB4D6; Wed, 21 Apr 2021 14:56:03 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a8511cc5-5931-4b24-a74b-bace21e8a439 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1619016964; h=from:from:reply-to: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=dn8xizhAj6dt285tHoUKq6uKJm2JGhL8Ej0gFCwHguo=; b=MFnylNO45EvnvRMzxksM5Fj45ojdxak99ir226m0Ju+/3yvh6yz0UsCVdKEE6fcy3yRZ76 /rJNBrC4FS+iqh2KstFVCIJ4jY8H4wsTijEUAp9XmnKJujciIV6ZeZxvWxzzGYAF/xdxqt HbhqV09TBt5LgFr+8NrCfib/zBiaePw= Subject: [PATCH v2 1/8] x86/MCE: avoid effectively open-coding xmalloc_array() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Wei Liu , =?utf-8?q?R?= =?utf-8?q?oger_Pau_Monn=C3=A9?= References: <091b4b91-712f-3526-78d1-80d31faf8e41@suse.com> Message-ID: <631d4b11-cfc5-c609-6169-28ba08aa978c@suse.com> Date: Wed, 21 Apr 2021 16:56:03 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <091b4b91-712f-3526-78d1-80d31faf8e41@suse.com> Content-Language: en-US There is a difference in generated code: xmalloc_bytes() forces SMP_CACHE_BYTES alignment. But if code really cared about such higher than default alignment, it should request so explicitly rather than using a type-unsafe interface. And if e.g. cache line sharing was a concern, the allocator itself should arrange to avoid such. Signed-off-by: Jan Beulich --- a/xen/arch/x86/cpu/mcheck/mctelem.c +++ b/xen/arch/x86/cpu/mcheck/mctelem.c @@ -345,7 +345,7 @@ void __init mctelem_init(unsigned int da if ((mctctl.mctc_elems = xmalloc_array(struct mctelem_ent, MC_NENT)) == NULL || - (datarr = xmalloc_bytes(MC_NENT * datasz)) == NULL) { + (datarr = xmalloc_array(char, MC_NENT * datasz)) == NULL) { xfree(mctctl.mctc_elems); printk("Allocations for MCA telemetry failed\n"); return; From patchwork Wed Apr 21 14:56:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12216321 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E657C433B4 for ; Wed, 21 Apr 2021 14:56:46 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0E37561430 for ; Wed, 21 Apr 2021 14:56:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0E37561430 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.114788.218809 (Exim 4.92) (envelope-from ) id 1lZEHN-0007yc-BH; Wed, 21 Apr 2021 14:56:37 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 114788.218809; Wed, 21 Apr 2021 14:56:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZEHN-0007yU-88; Wed, 21 Apr 2021 14:56:37 +0000 Received: by outflank-mailman (input) for mailman id 114788; Wed, 21 Apr 2021 14:56:35 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZEHL-0007yG-92 for xen-devel@lists.xenproject.org; Wed, 21 Apr 2021 14:56:35 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id eaf0465f-6f39-4fa3-85b3-2b310311ebfc; Wed, 21 Apr 2021 14:56:34 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 995EBAD8A; Wed, 21 Apr 2021 14:56:33 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: eaf0465f-6f39-4fa3-85b3-2b310311ebfc X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1619016993; h=from:from:reply-to: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=0hiOnsYBKJJyY/OKqVdi3PZ5qXRAtnLxQ2fMzsttxVs=; b=YkEJ7t+xIMGDyZM7Qp7QFZv3vodtNbLlNSZYSXvVpEYHO46U2S3Z6z4eDDf3OAjDnTbFV2 F6aQxPtgPTvLPKJ6d2rBJhCT2TrgEws68wp5UerVuPqURgfDgiG3IW6+PXdn1y/12MlBkZ KYSrxY/mV1tKcV0Bj22ueyqCJ8IN3vA= Subject: [PATCH v2 2/8] x86/HVM: avoid effectively open-coding xmalloc_array() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Wei Liu , =?utf-8?q?R?= =?utf-8?q?oger_Pau_Monn=C3=A9?= , Paul Durrant References: <091b4b91-712f-3526-78d1-80d31faf8e41@suse.com> Message-ID: <1c3d573d-051f-3d18-cd63-6ccad5911786@suse.com> Date: Wed, 21 Apr 2021 16:56:33 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <091b4b91-712f-3526-78d1-80d31faf8e41@suse.com> Content-Language: en-US There is a difference in generated code: xmalloc_bytes() forces SMP_CACHE_BYTES alignment. But if code really cared about such higher than default alignment, it should request so explicitly rather than using a type-unsafe interface. And if e.g. cache line sharing was a concern, the allocator itself should arrange to avoid such. Signed-off-by: Jan Beulich --- a/xen/arch/x86/hvm/emulate.c +++ b/xen/arch/x86/hvm/emulate.c @@ -1924,7 +1924,7 @@ static int hvmemul_rep_movs( dgpa -= bytes - bytes_per_rep; /* Allocate temporary buffer. Fall back to slow emulation if this fails. */ - buf = xmalloc_bytes(bytes); + buf = xmalloc_array(char, bytes); if ( buf == NULL ) return X86EMUL_UNHANDLEABLE; @@ -2037,7 +2037,7 @@ static int hvmemul_rep_stos( for ( ; ; ) { bytes = *reps * bytes_per_rep; - buf = xmalloc_bytes(bytes); + buf = xmalloc_array(char, bytes); if ( buf || *reps <= 1 ) break; *reps >>= 1; From patchwork Wed Apr 21 14:57:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12216323 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6D846C43460 for ; Wed, 21 Apr 2021 14:57:16 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0346D6144B for ; Wed, 21 Apr 2021 14:57:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0346D6144B Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.114793.218821 (Exim 4.92) (envelope-from ) id 1lZEHr-00085f-M4; Wed, 21 Apr 2021 14:57:07 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 114793.218821; Wed, 21 Apr 2021 14:57:07 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZEHr-00085Y-Ie; Wed, 21 Apr 2021 14:57:07 +0000 Received: by outflank-mailman (input) for mailman id 114793; Wed, 21 Apr 2021 14:57:06 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZEHq-00085T-Or for xen-devel@lists.xenproject.org; Wed, 21 Apr 2021 14:57:06 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id a3adcfe3-4c17-47e2-9d9f-80c4a6a969d6; Wed, 21 Apr 2021 14:57:06 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 38E00B2E8; Wed, 21 Apr 2021 14:57:05 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a3adcfe3-4c17-47e2-9d9f-80c4a6a969d6 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1619017025; h=from:from:reply-to: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=7k33TZjSiUsbN7zoExMERbIp8QvBpYbbwHsyd9tlzWs=; b=q62m4aOxX+wB5j9D8t4usjgr7KIKvIjEuq5NvNqiaFHPtt66/72eiimjnj/CCMUqqEu5cg 94JZAoer9V0u0xTHI9kbF7AD6/PkZcv5SLEZP1q8IU/+ZYWzwEctQqBivgBC/4LD0JLGTv WuDguSwlqagj676qs4vl8Se+OICWBaQ= Subject: [PATCH v2 3/8] x86/oprofile: avoid effectively open-coding xmalloc_array() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Wei Liu , =?utf-8?q?R?= =?utf-8?q?oger_Pau_Monn=C3=A9?= References: <091b4b91-712f-3526-78d1-80d31faf8e41@suse.com> Message-ID: Date: Wed, 21 Apr 2021 16:57:04 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <091b4b91-712f-3526-78d1-80d31faf8e41@suse.com> Content-Language: en-US There is a difference in generated code: xmalloc_bytes() forces SMP_CACHE_BYTES alignment. But if code really cared about such higher than default alignment, it should request so explicitly rather than using a type-unsafe interface. And if e.g. cache line sharing was a concern, the allocator itself should arrange to avoid such. While at it also use XFREE() instead of open-coding it and change loop induction variable types. Signed-off-by: Jan Beulich --- a/xen/arch/x86/oprofile/nmi_int.c +++ b/xen/arch/x86/oprofile/nmi_int.c @@ -142,30 +142,29 @@ static void nmi_save_registers(void * du static void free_msrs(void) { - int i; + unsigned int i; + for (i = 0; i < nr_cpu_ids; ++i) { - xfree(cpu_msrs[i].counters); - cpu_msrs[i].counters = NULL; - xfree(cpu_msrs[i].controls); - cpu_msrs[i].controls = NULL; + XFREE(cpu_msrs[i].counters); + XFREE(cpu_msrs[i].controls); } } static int allocate_msrs(void) { + unsigned int i; int success = 1; - size_t controls_size = sizeof(struct op_msr) * model->num_controls; - size_t counters_size = sizeof(struct op_msr) * model->num_counters; - int i; for_each_online_cpu (i) { - cpu_msrs[i].counters = xmalloc_bytes(counters_size); + cpu_msrs[i].counters = xmalloc_array(struct op_msr, + model->num_counters); if (!cpu_msrs[i].counters) { success = 0; break; } - cpu_msrs[i].controls = xmalloc_bytes(controls_size); + cpu_msrs[i].controls = xmalloc_array(struct op_msr, + model->num_controls); if (!cpu_msrs[i].controls) { success = 0; break; From patchwork Wed Apr 21 14:57:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12216337 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E10BC433ED for ; Wed, 21 Apr 2021 14:57:41 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 366D461449 for ; Wed, 21 Apr 2021 14:57:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 366D461449 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.114796.218832 (Exim 4.92) (envelope-from ) id 1lZEIG-0008Cg-Uy; Wed, 21 Apr 2021 14:57:32 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 114796.218832; Wed, 21 Apr 2021 14:57:32 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZEIG-0008CY-Rk; Wed, 21 Apr 2021 14:57:32 +0000 Received: by outflank-mailman (input) for mailman id 114796; Wed, 21 Apr 2021 14:57:32 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZEIG-0008C3-2j for xen-devel@lists.xenproject.org; Wed, 21 Apr 2021 14:57:32 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 4d6531b3-bb27-4ca8-b846-0279e2bc27c4; Wed, 21 Apr 2021 14:57:28 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 15918B2E8; Wed, 21 Apr 2021 14:57:28 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 4d6531b3-bb27-4ca8-b846-0279e2bc27c4 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1619017048; h=from:from:reply-to: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=RGVbQa+GqVgOa2I76yheTEF5apAHeScJZb/syJB8fWc=; b=iCbgVqwxeyO8ueX3j8mD4gW5zxPGiIyrUDdwtYTpofx/l22VMOn7HAi8CArS2cP8VVHSXN xB0bdA86HaYqMjXByGH2jU7ZQMpcSZ0/jnRBc2PoisRihq18wEIHL/VEBSWswZmB7XEZhc zls4CFd5rPloiko0Z6H+waDyELBxx5w= Subject: [PATCH v2 4/8] x86/IRQ: avoid over-alignment in alloc_pirq_struct() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Wei Liu , =?utf-8?q?R?= =?utf-8?q?oger_Pau_Monn=C3=A9?= References: <091b4b91-712f-3526-78d1-80d31faf8e41@suse.com> Message-ID: <8906088c-d76a-12ac-31d3-1375016a2148@suse.com> Date: Wed, 21 Apr 2021 16:57:27 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <091b4b91-712f-3526-78d1-80d31faf8e41@suse.com> Content-Language: en-US In particular in the PV case xzalloc_bytes() forcing SMP_CACHE_BYTES alignment is counterproductive, as the allocation size there is only 40 bytes. And if the code really cared about such higher than default alignment, it should request so explicitly rather than using a type- unsafe interface. Plus if e.g. cache line sharing was a concern, the allocator itself should arrange to avoid such. Signed-off-by: Jan Beulich --- a/xen/arch/x86/irq.c +++ b/xen/arch/x86/irq.c @@ -1313,9 +1313,12 @@ void cleanup_domain_irq_mapping(struct d struct pirq *alloc_pirq_struct(struct domain *d) { - size_t sz = is_hvm_domain(d) ? sizeof(struct pirq) : - offsetof(struct pirq, arch.hvm); - struct pirq *pirq = xzalloc_bytes(sz); + union pirq_pv { + char space[offsetof(struct pirq, arch.hvm)]; + void *align; + }; + struct pirq *pirq = is_hvm_domain(d) ? xzalloc(struct pirq) + : (void *)xzalloc(union pirq_pv); if ( pirq ) { From patchwork Wed Apr 21 14:58:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12216339 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 504BDC433ED for ; Wed, 21 Apr 2021 14:58:22 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 047F56144B for ; Wed, 21 Apr 2021 14:58:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 047F56144B Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.114799.218845 (Exim 4.92) (envelope-from ) id 1lZEIw-0008Ju-7u; Wed, 21 Apr 2021 14:58:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 114799.218845; Wed, 21 Apr 2021 14:58:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZEIw-0008Jn-4G; Wed, 21 Apr 2021 14:58:14 +0000 Received: by outflank-mailman (input) for mailman id 114799; Wed, 21 Apr 2021 14:58:13 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZEIv-0008Jg-8h for xen-devel@lists.xenproject.org; Wed, 21 Apr 2021 14:58:13 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id fd55a24a-ca85-42bd-bf69-2fd0fdeb40ff; Wed, 21 Apr 2021 14:58:12 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 91783B4F5; Wed, 21 Apr 2021 14:58:11 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: fd55a24a-ca85-42bd-bf69-2fd0fdeb40ff X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1619017091; h=from:from:reply-to: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=PW+XxMcrclQ3Woj7YTyYCjraRWb4WLw8fXwPv9OBWoI=; b=C5iUJDEKmDytH3E/JE6ybsGGTSClh2t7iobc0KwmwvYv+5WL05v1VfGIUSQAMmz/6WqY9B uiXjCRaTDs+8sxk1K1Y9KBK+9lm3Iz2ezOGyOjR/0OTHEwcqz6br8qb8VyD6xI4If6Dlr3 U/A1gnd2nudemy02NM7BHM6W0ArZmPM= Subject: [PATCH v2 5/8] EFI/runtime: avoid effectively open-coding x{m,z}alloc_array() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Ian Jackson , Julien Grall , Stefano Stabellini , Wei Liu References: <091b4b91-712f-3526-78d1-80d31faf8e41@suse.com> Message-ID: Date: Wed, 21 Apr 2021 16:58:11 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <091b4b91-712f-3526-78d1-80d31faf8e41@suse.com> Content-Language: en-US There is a difference in generated code: x{m,z}alloc_bytes() forces SMP_CACHE_BYTES alignment. But if code really cared about such higher than default alignment, it should request so explicitly rather than using a type-unsafe interface. And if e.g. cache line sharing was a concern, the allocator itself should arrange to avoid such. Signed-off-by: Jan Beulich --- a/xen/common/efi/runtime.c +++ b/xen/common/efi/runtime.c @@ -486,7 +486,7 @@ int efi_runtime_call(struct xenpf_efi_ru size = op->u.get_variable.size; if ( size ) { - data = xmalloc_bytes(size); + data = xmalloc_array(unsigned char, size); if ( !data ) { xfree(name); @@ -536,7 +536,7 @@ int efi_runtime_call(struct xenpf_efi_ru return -EIO; } - data = xmalloc_bytes(op->u.set_variable.size); + data = xmalloc_array(unsigned char, op->u.set_variable.size); if ( !data ) rc = -ENOMEM; else if ( copy_from_guest(data, op->u.set_variable.data, @@ -571,7 +571,7 @@ int efi_runtime_call(struct xenpf_efi_ru return -EINVAL; size = op->u.get_next_variable_name.size; - name.raw = xzalloc_bytes(size); + name.raw = xzalloc_array(unsigned char, size); if ( !name.raw ) return -ENOMEM; if ( copy_from_guest(name.raw, op->u.get_next_variable_name.name, From patchwork Wed Apr 21 14:58:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12216341 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79E28C433B4 for ; Wed, 21 Apr 2021 14:59:00 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2376C6144D for ; Wed, 21 Apr 2021 14:59:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2376C6144D Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.114802.218857 (Exim 4.92) (envelope-from ) id 1lZEJX-0008Rg-GL; Wed, 21 Apr 2021 14:58:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 114802.218857; Wed, 21 Apr 2021 14:58:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZEJX-0008RZ-DD; Wed, 21 Apr 2021 14:58:51 +0000 Received: by outflank-mailman (input) for mailman id 114802; Wed, 21 Apr 2021 14:58:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZEJV-0008RJ-R6 for xen-devel@lists.xenproject.org; Wed, 21 Apr 2021 14:58:49 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ec5dbab9-d98d-48be-ae11-d491971b14e5; Wed, 21 Apr 2021 14:58:49 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 4E330B4D5; Wed, 21 Apr 2021 14:58:48 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ec5dbab9-d98d-48be-ae11-d491971b14e5 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1619017128; h=from:from:reply-to: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=TEBD/fYXGTJrgtLtgU6ekKg6T1yeMv6RYI14JcXg8j8=; b=c1iQM0N8Kr/7EMMA3fDMO/lAq3vlxDYh+Qu+6yeO5vSsNcW3uc5pvAUBgKtyuudjrWINRx 9XEv1TLdeMKPxZeZCZD19wWaF0rINC3StebQxVMf3rY7UawdDIgHWZoBZHqSxeTFvEe5Yc FbDBohSc2bSuuFNvyT4cwW4HRj88EDw= Subject: [PATCH v2 6/8] kexec: avoid effectively open-coding xzalloc_flex_struct() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap References: <091b4b91-712f-3526-78d1-80d31faf8e41@suse.com> Message-ID: <7d6c30d8-c121-11f5-4ac9-49bad43a2a19@suse.com> Date: Wed, 21 Apr 2021 16:58:48 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <091b4b91-712f-3526-78d1-80d31faf8e41@suse.com> Content-Language: en-US There is a difference in generated code: xzalloc_bytes() forces SMP_CACHE_BYTES alignment. But if code really cared about such higher than default alignment, it should request so explicitly rather than using a type-unsafe interface. And if e.g. cache line sharing was a concern, the allocator itself should arrange to avoid such. Signed-off-by: Jan Beulich --- a/xen/common/kexec.c +++ b/xen/common/kexec.c @@ -463,7 +463,10 @@ static void * alloc_from_crash_heap(cons /* Allocate a crash note buffer for a newly onlined cpu. */ static int kexec_init_cpu_notes(const unsigned long cpu) { - Elf_Note * note = NULL; + struct elf_notes { + Elf_Note first; + unsigned char more[]; + } *notes = NULL; int ret = 0; int nr_bytes = 0; @@ -477,7 +480,8 @@ static int kexec_init_cpu_notes(const un /* If we dont care about the position of allocation, malloc. */ if ( low_crashinfo_mode == LOW_CRASHINFO_NONE ) - note = xzalloc_bytes(nr_bytes); + notes = xzalloc_flex_struct(struct elf_notes, more, + nr_bytes - sizeof(notes->first)); /* Protect the write into crash_notes[] with a spinlock, as this function * is on a hotplug path and a hypercall path. */ @@ -490,26 +494,28 @@ static int kexec_init_cpu_notes(const un spin_unlock(&crash_notes_lock); /* Always return ok, because whether we successfully allocated or not, * another CPU has successfully allocated. */ - xfree(note); + xfree(notes); } else { /* If we care about memory possition, alloc from the crash heap, * also protected by the crash_notes_lock. */ if ( low_crashinfo_mode > LOW_CRASHINFO_NONE ) - note = alloc_from_crash_heap(nr_bytes); + notes = alloc_from_crash_heap(nr_bytes); - crash_notes[cpu].start = note; + crash_notes[cpu].start = ¬es->first; crash_notes[cpu].size = nr_bytes; spin_unlock(&crash_notes_lock); /* If the allocation failed, and another CPU did not beat us, give * up with ENOMEM. */ - if ( ! note ) + if ( ! notes ) ret = -ENOMEM; /* else all is good so lets set up the notes. */ else { + Elf_Note *note = ¬es->first; + /* Set up CORE note. */ setup_note(note, "CORE", NT_PRSTATUS, sizeof(ELF_Prstatus)); note = ELFNOTE_NEXT(note); From patchwork Wed Apr 21 14:59:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12216343 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A4A8C433B4 for ; Wed, 21 Apr 2021 14:59:34 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C611B61449 for ; Wed, 21 Apr 2021 14:59:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C611B61449 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.114807.218869 (Exim 4.92) (envelope-from ) id 1lZEK5-00007f-Pl; Wed, 21 Apr 2021 14:59:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 114807.218869; Wed, 21 Apr 2021 14:59:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZEK5-00007Y-Mj; Wed, 21 Apr 2021 14:59:25 +0000 Received: by outflank-mailman (input) for mailman id 114807; Wed, 21 Apr 2021 14:59:24 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZEK4-00007P-2L for xen-devel@lists.xenproject.org; Wed, 21 Apr 2021 14:59:24 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id eb545c1f-b181-4c0d-8095-121634ccc030; Wed, 21 Apr 2021 14:59:23 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 96707B2E8; Wed, 21 Apr 2021 14:59:22 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: eb545c1f-b181-4c0d-8095-121634ccc030 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1619017162; h=from:from:reply-to: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=nhFCzQarQALIvmpTT7NHPYBbPtP6KFRVyXEIq1mQnM0=; b=GhiK152G4eeoBnhZPFiTgN3IYWdzhp+HZSNtN1UyFJWY5l6C8SAUjYkEptpyyJ2dS5g7Uc LcXzQsB1yhXfBrT7CIwcOvepJKqoFbEQghzv7QF94iqB6axNI320hTjXexsPSdZHihUjeg eub1OGxUWCoWwRywXgpTSJ+G+CVWRV8= Subject: [PATCH v2 7/8] video/lfb: avoid effectively open-coding xzalloc_array() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Ian Jackson , Julien Grall , Stefano Stabellini , Wei Liu References: <091b4b91-712f-3526-78d1-80d31faf8e41@suse.com> Message-ID: <73db0f74-438e-d99f-35d7-76679df75e40@suse.com> Date: Wed, 21 Apr 2021 16:59:22 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <091b4b91-712f-3526-78d1-80d31faf8e41@suse.com> Content-Language: en-US There is a difference in generated code: xzalloc_bytes() forces SMP_CACHE_BYTES alignment. But if code really cared about such higher than default alignment, it should request so explicitly rather than using a type-unsafe interface. And if e.g. cache line sharing was a concern, the allocator itself should arrange to avoid such. Signed-off-by: Jan Beulich --- a/xen/drivers/video/lfb.c +++ b/xen/drivers/video/lfb.c @@ -147,8 +147,9 @@ int __init lfb_init(struct lfb_prop *lfb { lfb.lfbp = *lfbp; - lfb.lbuf = xmalloc_bytes(lfb.lfbp.bytes_per_line); - lfb.text_buf = xzalloc_bytes(lfb.lfbp.text_columns * lfb.lfbp.text_rows); + lfb.lbuf = xmalloc_array(unsigned char, lfb.lfbp.bytes_per_line); + lfb.text_buf = xzalloc_array(unsigned char, + lfb.lfbp.text_columns * lfb.lfbp.text_rows); lfb.line_len = xzalloc_array(unsigned int, lfb.lfbp.text_columns); if ( !lfb.lbuf || !lfb.text_buf || !lfb.line_len ) From patchwork Wed Apr 21 14:59:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 12216345 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 406DAC433ED for ; Wed, 21 Apr 2021 15:00:13 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D8C916145B for ; Wed, 21 Apr 2021 15:00:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D8C916145B Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.114812.218881 (Exim 4.92) (envelope-from ) id 1lZEKf-0000FJ-3Q; Wed, 21 Apr 2021 15:00:01 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 114812.218881; Wed, 21 Apr 2021 15:00:01 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZEKe-0000FC-W3; Wed, 21 Apr 2021 15:00:00 +0000 Received: by outflank-mailman (input) for mailman id 114812; Wed, 21 Apr 2021 15:00:00 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lZEKe-0000F4-ED for xen-devel@lists.xenproject.org; Wed, 21 Apr 2021 15:00:00 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 83f04db8-4b6e-4d95-a421-393bab35cd72; Wed, 21 Apr 2021 14:59:59 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id DC8D2B4D6; Wed, 21 Apr 2021 14:59:58 +0000 (UTC) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 83f04db8-4b6e-4d95-a421-393bab35cd72 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1619017199; h=from:from:reply-to: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=pHhwX5kEIhnRT5ymp9VtnAWZvoeCZfwBmTwU5SVmNWE=; b=b+LZks+synfdec+zvPWSzh2ua/VRk7fxpTdmfsCVAE518Ko5xFyviQme1dI5d/B2v44Fv9 m4F8/GhNNv8ZM99nt7gyFH9FUVF90cBDMRW3Zqr6tTr80TyqDZhEBngiwkopiKUvUu4W5Z c/JBIUeQyEw7Cr1b61W6UNOTpEkFZM4= Subject: [PATCH v2 8/8] Arm/optee: don't open-code xzalloc_flex_struct() From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: George Dunlap , Julien Grall , Stefano Stabellini References: <091b4b91-712f-3526-78d1-80d31faf8e41@suse.com> Message-ID: <5fa042ac-9609-eab7-b14d-a59782ef4141@suse.com> Date: Wed, 21 Apr 2021 16:59:58 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <091b4b91-712f-3526-78d1-80d31faf8e41@suse.com> Content-Language: en-US The current use of xzalloc_bytes() in optee is nearly an open-coded version of xzalloc_flex_struct(), which was introduced after the driver was merged. The main difference is xzalloc_bytes() will also force the allocation to be SMP_CACHE_BYTES aligned and therefore avoid sharing the cache line. While sharing the cache line can have an impact on the performance, this is also true for most of the other users of x*alloc(), x*alloc_array(), and x*alloc_flex_struct(). So if we want to prevent sharing cache lines, arranging for this should be done in the allocator itself. In this case, we don't need stricter alignment than what the allocator provides. Hence replace the call to xzalloc_bytes() with one of xzalloc_flex_struct(). Signed-off-by: Jan Beulich Signed-off-by: Julien Grall Acked-by: Volodymyr Babchuk --- v2: Use commit message very close to what was suggested by Julien. --- a/xen/arch/arm/tee/optee.c +++ b/xen/arch/arm/tee/optee.c @@ -529,8 +529,7 @@ static struct optee_shm_buf *allocate_op while ( unlikely(old != atomic_cmpxchg(&ctx->optee_shm_buf_pages, old, new)) ); - optee_shm_buf = xzalloc_bytes(sizeof(struct optee_shm_buf) + - pages_cnt * sizeof(struct page *)); + optee_shm_buf = xzalloc_flex_struct(struct optee_shm_buf, pages, pages_cnt); if ( !optee_shm_buf ) { err_code = -ENOMEM;