From: Paolo Bonzini Date: Wed, 11 Aug 2021 10:53:17 +0000 Subject: Re: [PATCH v3 1/5] KVM: stats: Support linear and logarithmic histogram statistics Message-Id: List-Id: References: <20210802165633.1866976-1-jingzhangos@google.com> <20210802165633.1866976-2-jingzhangos@google.com> In-Reply-To: <20210802165633.1866976-2-jingzhangos@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: Jing Zhang , KVM , KVMPPC , Sean Christopherson , Jim Mattson , Peter Shier , Oliver Upton , David Rientjes , David Matlack On 02/08/21 18:56, Jing Zhang wrote: > + index = array_index_nospec(index, size); > + ++data[index]; This would have to use index = min(index, size-1); index = array_index_nospec(index, size); But thinking more about it there should be no way to do *two* consecutive accesses. Thus, it would be possible to bring an out of bounds element of data[] in the cache, but it would not be possible to deduce its value. This might have to be taken into account when adding more statistics, but for now I've simply replaced array_index_nospec with the min() above. Paolo