From: Laurent Vivier <laurent@vivier.eu>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: patches@linaro.org, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
Subject: Re: [Qemu-devel] [RFC 2/3] target/m68k: In get_physical_address() check for memory access failures
Date: Fri, 3 May 2019 18:46:05 +0200 [thread overview]
Message-ID: <57e90be8-0652-8204-cc9e-1ce347e446d8@vivier.eu> (raw)
In-Reply-To: <20181210165636.28366-3-peter.maydell@linaro.org>
On 10/12/2018 17:56, Peter Maydell wrote:
> In get_physical_address(), use address_space_ldl() and
> address_space_stl() instead of ldl_phys() and stl_phys().
> This allows us to check whether the memory access failed.
> For the moment, we simply return -1 in this case;
> add a TODO comment that we should ideally generate the
> appropriate kind of fault.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> target/m68k/helper.c | 62 +++++++++++++++++++++++++++++++++++++-------
> 1 file changed, 52 insertions(+), 10 deletions(-)
>
> diff --git a/target/m68k/helper.c b/target/m68k/helper.c
> index 374e4861886..b5fa2f8056d 100644
> --- a/target/m68k/helper.c
> +++ b/target/m68k/helper.c
> @@ -660,6 +660,7 @@ static int get_physical_address(CPUM68KState *env, hwaddr *physical,
> bool debug = access_type & ACCESS_DEBUG;
> int page_bits;
> int i;
> + MemTxResult txres;
>
> /* Transparent Translation (physical = logical) */
> for (i = 0; i < M68K_MAX_TTR; i++) {
> @@ -689,12 +690,19 @@ static int get_physical_address(CPUM68KState *env, hwaddr *physical,
> /* Root Index */
> entry = M68K_POINTER_BASE(next) | M68K_ROOT_INDEX(address);
>
> - next = ldl_phys(cs->as, entry);
> + next = address_space_ldl(cs->as, entry, MEMTXATTRS_UNSPECIFIED, &txres);
> + if (txres != MEMTX_OK) {
> + goto txfail;
> + }
> if (!M68K_UDT_VALID(next)) {
> return -1;
> }
> if (!(next & M68K_DESC_USED) && !debug) {
> - stl_phys(cs->as, entry, next | M68K_DESC_USED);
> + address_space_stl(cs->as, entry, next | M68K_DESC_USED,
> + MEMTXATTRS_UNSPECIFIED, &txres);
> + if (txres != MEMTX_OK) {
> + goto txfail;
> + }
> }
> if (next & M68K_DESC_WRITEPROT) {
> if (access_type & ACCESS_PTEST) {
> @@ -709,12 +717,19 @@ static int get_physical_address(CPUM68KState *env, hwaddr *physical,
> /* Pointer Index */
> entry = M68K_POINTER_BASE(next) | M68K_POINTER_INDEX(address);
>
> - next = ldl_phys(cs->as, entry);
> + next = address_space_ldl(cs->as, entry, MEMTXATTRS_UNSPECIFIED, &txres);
> + if (txres != MEMTX_OK) {
> + goto txfail;
> + }
> if (!M68K_UDT_VALID(next)) {
> return -1;
> }
> if (!(next & M68K_DESC_USED) && !debug) {
> - stl_phys(cs->as, entry, next | M68K_DESC_USED);
> + address_space_stl(cs->as, entry, next | M68K_DESC_USED,
> + MEMTXATTRS_UNSPECIFIED, &txres);
> + if (txres != MEMTX_OK) {
> + goto txfail;
> + }
> }
> if (next & M68K_DESC_WRITEPROT) {
> if (access_type & ACCESS_PTEST) {
> @@ -733,27 +748,46 @@ static int get_physical_address(CPUM68KState *env, hwaddr *physical,
> entry = M68K_4K_PAGE_BASE(next) | M68K_4K_PAGE_INDEX(address);
> }
>
> - next = ldl_phys(cs->as, entry);
> + next = address_space_ldl(cs->as, entry, MEMTXATTRS_UNSPECIFIED, &txres);
> + if (txres != MEMTX_OK) {
> + goto txfail;
> + }
>
> if (!M68K_PDT_VALID(next)) {
> return -1;
> }
> if (M68K_PDT_INDIRECT(next)) {
> - next = ldl_phys(cs->as, M68K_INDIRECT_POINTER(next));
> + next = address_space_ldl(cs->as, M68K_INDIRECT_POINTER(next),
> + MEMTXATTRS_UNSPECIFIED, &txres);
> + if (txres != MEMTX_OK) {
> + goto txfail;
> + }
> }
> if (access_type & ACCESS_STORE) {
> if (next & M68K_DESC_WRITEPROT) {
> if (!(next & M68K_DESC_USED) && !debug) {
> - stl_phys(cs->as, entry, next | M68K_DESC_USED);
> + address_space_stl(cs->as, entry, next | M68K_DESC_USED,
> + MEMTXATTRS_UNSPECIFIED, &txres);
> + if (txres != MEMTX_OK) {
> + goto txfail;
> + }
> }
> } else if ((next & (M68K_DESC_MODIFIED | M68K_DESC_USED)) !=
> (M68K_DESC_MODIFIED | M68K_DESC_USED) && !debug) {
> - stl_phys(cs->as, entry,
> - next | (M68K_DESC_MODIFIED | M68K_DESC_USED));
> + address_space_stl(cs->as, entry,
> + next | (M68K_DESC_MODIFIED | M68K_DESC_USED),
> + MEMTXATTRS_UNSPECIFIED, &txres);
> + if (txres != MEMTX_OK) {
> + goto txfail;
> + }
> }
> } else {
> if (!(next & M68K_DESC_USED) && !debug) {
> - stl_phys(cs->as, entry, next | M68K_DESC_USED);
> + address_space_stl(cs->as, entry, next | M68K_DESC_USED,
> + MEMTXATTRS_UNSPECIFIED, &txres);
> + if (txres != MEMTX_OK) {
> + goto txfail;
> + }
> }
> }
>
> @@ -785,6 +819,14 @@ static int get_physical_address(CPUM68KState *env, hwaddr *physical,
> }
>
> return 0;
> +
> +txfail:
> + /*
> + * A page table load/store failed. TODO: we should really raise a
> + * suitable guest fault here if this is not a debug access.
> + * For now just return that the translation failed.
> + */
> + return -1;
> }
>
> hwaddr m68k_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
WARNING: multiple messages have this Message-ID (diff)
From: Laurent Vivier <laurent@vivier.eu>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, patches@linaro.org
Subject: Re: [Qemu-devel] [RFC 2/3] target/m68k: In get_physical_address() check for memory access failures
Date: Fri, 3 May 2019 18:46:05 +0200 [thread overview]
Message-ID: <57e90be8-0652-8204-cc9e-1ce347e446d8@vivier.eu> (raw)
Message-ID: <20190503164605.r-H7O78cyAGRoJSwCNrLCWBRLvSetnZ_ZJGK66_5GEg@z> (raw)
In-Reply-To: <20181210165636.28366-3-peter.maydell@linaro.org>
On 10/12/2018 17:56, Peter Maydell wrote:
> In get_physical_address(), use address_space_ldl() and
> address_space_stl() instead of ldl_phys() and stl_phys().
> This allows us to check whether the memory access failed.
> For the moment, we simply return -1 in this case;
> add a TODO comment that we should ideally generate the
> appropriate kind of fault.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> target/m68k/helper.c | 62 +++++++++++++++++++++++++++++++++++++-------
> 1 file changed, 52 insertions(+), 10 deletions(-)
>
> diff --git a/target/m68k/helper.c b/target/m68k/helper.c
> index 374e4861886..b5fa2f8056d 100644
> --- a/target/m68k/helper.c
> +++ b/target/m68k/helper.c
> @@ -660,6 +660,7 @@ static int get_physical_address(CPUM68KState *env, hwaddr *physical,
> bool debug = access_type & ACCESS_DEBUG;
> int page_bits;
> int i;
> + MemTxResult txres;
>
> /* Transparent Translation (physical = logical) */
> for (i = 0; i < M68K_MAX_TTR; i++) {
> @@ -689,12 +690,19 @@ static int get_physical_address(CPUM68KState *env, hwaddr *physical,
> /* Root Index */
> entry = M68K_POINTER_BASE(next) | M68K_ROOT_INDEX(address);
>
> - next = ldl_phys(cs->as, entry);
> + next = address_space_ldl(cs->as, entry, MEMTXATTRS_UNSPECIFIED, &txres);
> + if (txres != MEMTX_OK) {
> + goto txfail;
> + }
> if (!M68K_UDT_VALID(next)) {
> return -1;
> }
> if (!(next & M68K_DESC_USED) && !debug) {
> - stl_phys(cs->as, entry, next | M68K_DESC_USED);
> + address_space_stl(cs->as, entry, next | M68K_DESC_USED,
> + MEMTXATTRS_UNSPECIFIED, &txres);
> + if (txres != MEMTX_OK) {
> + goto txfail;
> + }
> }
> if (next & M68K_DESC_WRITEPROT) {
> if (access_type & ACCESS_PTEST) {
> @@ -709,12 +717,19 @@ static int get_physical_address(CPUM68KState *env, hwaddr *physical,
> /* Pointer Index */
> entry = M68K_POINTER_BASE(next) | M68K_POINTER_INDEX(address);
>
> - next = ldl_phys(cs->as, entry);
> + next = address_space_ldl(cs->as, entry, MEMTXATTRS_UNSPECIFIED, &txres);
> + if (txres != MEMTX_OK) {
> + goto txfail;
> + }
> if (!M68K_UDT_VALID(next)) {
> return -1;
> }
> if (!(next & M68K_DESC_USED) && !debug) {
> - stl_phys(cs->as, entry, next | M68K_DESC_USED);
> + address_space_stl(cs->as, entry, next | M68K_DESC_USED,
> + MEMTXATTRS_UNSPECIFIED, &txres);
> + if (txres != MEMTX_OK) {
> + goto txfail;
> + }
> }
> if (next & M68K_DESC_WRITEPROT) {
> if (access_type & ACCESS_PTEST) {
> @@ -733,27 +748,46 @@ static int get_physical_address(CPUM68KState *env, hwaddr *physical,
> entry = M68K_4K_PAGE_BASE(next) | M68K_4K_PAGE_INDEX(address);
> }
>
> - next = ldl_phys(cs->as, entry);
> + next = address_space_ldl(cs->as, entry, MEMTXATTRS_UNSPECIFIED, &txres);
> + if (txres != MEMTX_OK) {
> + goto txfail;
> + }
>
> if (!M68K_PDT_VALID(next)) {
> return -1;
> }
> if (M68K_PDT_INDIRECT(next)) {
> - next = ldl_phys(cs->as, M68K_INDIRECT_POINTER(next));
> + next = address_space_ldl(cs->as, M68K_INDIRECT_POINTER(next),
> + MEMTXATTRS_UNSPECIFIED, &txres);
> + if (txres != MEMTX_OK) {
> + goto txfail;
> + }
> }
> if (access_type & ACCESS_STORE) {
> if (next & M68K_DESC_WRITEPROT) {
> if (!(next & M68K_DESC_USED) && !debug) {
> - stl_phys(cs->as, entry, next | M68K_DESC_USED);
> + address_space_stl(cs->as, entry, next | M68K_DESC_USED,
> + MEMTXATTRS_UNSPECIFIED, &txres);
> + if (txres != MEMTX_OK) {
> + goto txfail;
> + }
> }
> } else if ((next & (M68K_DESC_MODIFIED | M68K_DESC_USED)) !=
> (M68K_DESC_MODIFIED | M68K_DESC_USED) && !debug) {
> - stl_phys(cs->as, entry,
> - next | (M68K_DESC_MODIFIED | M68K_DESC_USED));
> + address_space_stl(cs->as, entry,
> + next | (M68K_DESC_MODIFIED | M68K_DESC_USED),
> + MEMTXATTRS_UNSPECIFIED, &txres);
> + if (txres != MEMTX_OK) {
> + goto txfail;
> + }
> }
> } else {
> if (!(next & M68K_DESC_USED) && !debug) {
> - stl_phys(cs->as, entry, next | M68K_DESC_USED);
> + address_space_stl(cs->as, entry, next | M68K_DESC_USED,
> + MEMTXATTRS_UNSPECIFIED, &txres);
> + if (txres != MEMTX_OK) {
> + goto txfail;
> + }
> }
> }
>
> @@ -785,6 +819,14 @@ static int get_physical_address(CPUM68KState *env, hwaddr *physical,
> }
>
> return 0;
> +
> +txfail:
> + /*
> + * A page table load/store failed. TODO: we should really raise a
> + * suitable guest fault here if this is not a debug access.
> + * For now just return that the translation failed.
> + */
> + return -1;
> }
>
> hwaddr m68k_cpu_get_phys_page_debug(CPUState *cs, vaddr addr)
>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
next prev parent reply other threads:[~2019-05-03 16:46 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-10 16:56 [Qemu-devel] [RFC 0/3] target/m68k: convert to transaction_failed hook Peter Maydell
2018-12-10 16:56 ` [Qemu-devel] [RFC 1/3] target/m68k: In dump_address_map() check for memory access failures Peter Maydell
2019-05-03 16:40 ` Laurent Vivier
2019-05-03 16:40 ` Laurent Vivier
2018-12-10 16:56 ` [Qemu-devel] [RFC 2/3] target/m68k: In get_physical_address() " Peter Maydell
2019-05-03 16:46 ` Laurent Vivier [this message]
2019-05-03 16:46 ` Laurent Vivier
2018-12-10 16:56 ` [Qemu-devel] [RFC 3/3] target/m68k: Switch to transaction_failed hook Peter Maydell
2019-05-03 16:55 ` Laurent Vivier
2019-05-03 16:55 ` Laurent Vivier
2018-12-11 8:42 ` [Qemu-devel] [RFC 0/3] target/m68k: convert " Thomas Huth
2018-12-11 19:13 ` Mark Cave-Ayland
2018-12-11 19:29 ` Peter Maydell
2018-12-12 20:43 ` Laurent Vivier
2019-05-03 14:16 ` Peter Maydell
2019-05-03 14:16 ` Peter Maydell
2019-05-03 17:12 ` Laurent Vivier
2019-05-03 17:12 ` Laurent Vivier
2019-05-16 13:26 ` Peter Maydell
2019-05-16 13:36 ` Laurent Vivier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=57e90be8-0652-8204-cc9e-1ce347e446d8@vivier.eu \
--to=laurent@vivier.eu \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=patches@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).