From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-181.mta1.migadu.com (out-181.mta1.migadu.com [95.215.58.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DE2663B9920 for ; Fri, 26 Jun 2026 19:26:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782501974; cv=none; b=rb/ykvudIhYJoCa1iJpHThCFyKzFinGhcwF03Qqt5gb7hg+G0/4fZJ+Ku4x46L4jDLDT+anmuwRPCxQkBEsH6G/zQMuDmyrxz/wljgghHptr9WnwfLEpjDsQm4nLDigoPN7ExND8I8du7NvG7NymVkg5IOVRdEllDpPfuNX9SHg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782501974; c=relaxed/simple; bh=NlqLdOJpqgMo5o6mV1TUw4H5C3mTCkEvxRi8vLlIi/o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TgZkqG2HDwOT1zSwDOhd3hkoNUPqHHDyvxaeHXF+yDnQrwNKRugpcpQVBAPEGBWT9QbjuT/nem6gOuScOfw4AnIzCsWOkpq8VOABwQtaayjLAKFG0KobpoTobT0kBUzVm0BVNWgJhnHfKftJT9tMKCEIYePeHgwILXrUAxNIL2k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=tpBodHKL; arc=none smtp.client-ip=95.215.58.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="tpBodHKL" Date: Fri, 26 Jun 2026 21:25:47 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1782501970; 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: in-reply-to:in-reply-to:references:references; bh=P3GSIxg28qBTx+sEiExtBNcC25BVatGs6EWV34pDMZM=; b=tpBodHKLZlJSwypwSQlX0z4HMwd1UTkj/mNZRFfM9CfiC4L/gi8FxWj+J3kZf3o9bskpB5 YiH1AzaFLgaINdJ9mnz8ZhRbiPpDfJ6zZ80VKwkKQlESyoliLYLcwzyHkXTvCpiD4auNEL f92KJMC1nyb2rdkySJCrQgp4YUyhL/g= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Thorsten Blum To: Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , "Christophe Leroy (CS GROUP)" Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] powerpc/pseries/ras: Use struct_size() to simplify fwnmi_get_errinfo() Message-ID: References: <20260626184750.166642-3-thorsten.blum@linux.dev> <20260626184750.166642-4-thorsten.blum@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260626184750.166642-4-thorsten.blum@linux.dev> X-Migadu-Flow: FLOW_OUT On Fri, Jun 26, 2026 at 08:47:50PM +0200, Thorsten Blum wrote: > Now that struct rtas_error_log uses a flexible array member for the > extended log buffer, use struct_size() to calculate the total RTAS error > log size and avoid using the hard-coded header size of 8 bytes. > > Use memcpy_and_pad() instead of memset() and memcpy() while at it. > > Signed-off-by: Thorsten Blum > --- > arch/powerpc/platforms/pseries/ras.c | 17 +++++++---------- > 1 file changed, 7 insertions(+), 10 deletions(-) > > diff --git a/arch/powerpc/platforms/pseries/ras.c b/arch/powerpc/platforms/pseries/ras.c > index adafd593d9d3..d54030fd2324 100644 > --- a/arch/powerpc/platforms/pseries/ras.c > +++ b/arch/powerpc/platforms/pseries/ras.c > @@ -7,6 +7,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -440,6 +441,8 @@ static __be64 *fwnmi_get_savep(struct pt_regs *regs) > static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs) > { > struct rtas_error_log *h; > + u32 extended_log_length; > + size_t len; > __be64 *savep; > > savep = fwnmi_get_savep(regs); > @@ -449,17 +452,11 @@ static struct rtas_error_log *fwnmi_get_errinfo(struct pt_regs *regs) > regs->gpr[3] = be64_to_cpu(savep[0]); /* restore original r3 */ > > h = (struct rtas_error_log *)&savep[1]; > + extended_log_length = rtas_error_extended(h) ? rtas_error_extended_log_length(h) : 0; > + len = struct_size(h, buffer, extended_log_length); > + len = min(len, RTAS_ERROR_LOG_MAX); > /* Use the per cpu buffer from paca to store rtas error log */ > - memset(local_paca->mce_data_buf, 0, RTAS_ERROR_LOG_MAX); > - if (!rtas_error_extended(h)) { > - memcpy(local_paca->mce_data_buf, h, sizeof(__u64)); > - } else { > - int len, error_log_length; > - > - error_log_length = 8 + rtas_error_extended_log_length(h); > - len = min_t(int, error_log_length, RTAS_ERROR_LOG_MAX); > - memcpy(local_paca->mce_data_buf, h, len); > - } > + memcpy_and_pad(local_paca->mce_data_buf, RTAS_ERROR_LOG_MAX, h, len, 0); Sashiko found that memcpy_and_pad() isn't safe here because fwnmi_get_errinfo() is part of a real-mode path: https://sashiko.dev/#/patchset/20260626184750.166642-3-thorsten.blum%40linux.dev I'll send a v2 and keep memset() and memcpy() separate.