Skip to content

Commit

Permalink
Merge tag 'pull-tcg-20240424' of https://gitlab.com/rth7680/qemu into…
Browse files Browse the repository at this point in the history
… staging

meson: Make DEBUG_REMAP a meson option
target/m68k: Support semihosting on non-ColdFire targets
linux-user: do_setsockopt cleanups
linux-user: Add FITRIM ioctl

# -----BEGIN PGP SIGNATURE-----
#
# iQFRBAABCgA7FiEEekgeeIaLTbaoWgXAZN846K9+IV8FAmYpjHcdHHJpY2hhcmQu
# aGVuZGVyc29uQGxpbmFyby5vcmcACgkQZN846K9+IV+a/Af7BHmDB27U61b9i8et
# cObewYH9y9M+iaCrIflNZPAaoguHDRKOuvw+PFT/dIo5FL2D509vYOuxUow1qLsy
# q6b6kdvXROq9WU2NiuB86Abl/4mwwzxRhFah+Eh+OYSA2/pQnkcULkouLqxjFfF0
# xTBzZtHtYdTbCTVRbpd6XrwLo7Qrs85ovl4wVD1r+T2T8FkvrryoNOA/VjUWxyeh
# 3b1X1I0wtOTnEA7JSr17JCXWZGENCmTO35r6WSYzJy5U/C59PjjgaaeMi3R3lQTJ
# gg21EH0hlU1nTiPLg2ypj3l9NbIGAincAdDF/jufee+R75YSPdpKoDH8tUlUGsnM
# CRx5Xg==
# =J+5K
# -----END PGP SIGNATURE-----
# gpg: Signature made Wed 24 Apr 2024 03:49:27 PM PDT
# gpg:                using RSA key 7A481E78868B4DB6A85A05C064DF38E8AF7E215F
# gpg:                issuer "richard.henderson@linaro.org"
# gpg: Good signature from "Richard Henderson <richard.henderson@linaro.org>" [ultimate]

* tag 'pull-tcg-20240424' of https://gitlab.com/rth7680/qemu:
  target/m68k: Support semihosting on non-ColdFire targets
  target/m68k: Perform the semihosting test during translate
  target/m68k: Pass semihosting arg to exit
  linux-user: Add FITRIM ioctl
  linux-user: do_setsockopt: eliminate goto in switch for SO_SNDTIMEO
  linux-user: do_setsockopt: make ip_mreq_source local to the place where it is used
  linux-user: do_setsockopt: make ip_mreq local to the place it is used and inline target_to_host_ip_mreq()
  linux-user: do_setsockopt: fix SOL_ALG.ALG_SET_KEY
  meson: Make DEBUG_REMAP a meson option

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
  • Loading branch information
rth7680 committed Apr 24, 2024
2 parents 85b5974 + 0815c22 commit 5da7219
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 68 deletions.
6 changes: 2 additions & 4 deletions bsd-user/qemu.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
#include "exec/cpu_ldst.h"
#include "exec/exec-all.h"

#undef DEBUG_REMAP

#include "exec/user/abitypes.h"

extern char **environ;
Expand Down Expand Up @@ -437,7 +435,7 @@ static inline void *lock_user(int type, abi_ulong guest_addr, long len,
if (!access_ok(type, guest_addr, len)) {
return NULL;
}
#ifdef DEBUG_REMAP
#ifdef CONFIG_DEBUG_REMAP
{
void *addr;
addr = g_malloc(len);
Expand All @@ -461,7 +459,7 @@ static inline void unlock_user(void *host_ptr, abi_ulong guest_addr,
long len)
{

#ifdef DEBUG_REMAP
#ifdef CONFIG_DEBUG_REMAP
if (!host_ptr) {
return;
}
Expand Down
3 changes: 3 additions & 0 deletions linux-user/ioctls.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@
#ifdef FITHAW
IOCTL(FITHAW, IOC_W | IOC_R, TYPE_INT)
#endif
#ifdef FITRIM
IOCTL(FITRIM, IOC_W | IOC_R, MK_PTR(MK_STRUCT(STRUCT_fstrim_range)))
#endif

IOCTL(FIGETBSZ, IOC_R, MK_PTR(TYPE_LONG))
#ifdef CONFIG_FIEMAP
Expand Down
4 changes: 1 addition & 3 deletions linux-user/qemu.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include "cpu.h"
#include "exec/cpu_ldst.h"

#undef DEBUG_REMAP

#include "exec/user/abitypes.h"

#include "syscall_defs.h"
Expand Down Expand Up @@ -332,7 +330,7 @@ void *lock_user(int type, abi_ulong guest_addr, ssize_t len, bool copy);
/* Unlock an area of guest memory. The first LEN bytes must be
flushed back to guest memory. host_ptr = NULL is explicitly
allowed and does nothing. */
#ifndef DEBUG_REMAP
#ifndef CONFIG_DEBUG_REMAP
static inline void unlock_user(void *host_ptr, abi_ulong guest_addr,
ssize_t len)
{
Expand Down
73 changes: 33 additions & 40 deletions linux-user/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -1615,24 +1615,6 @@ static abi_long do_pipe(CPUArchState *cpu_env, abi_ulong pipedes,
return get_errno(ret);
}

static inline abi_long target_to_host_ip_mreq(struct ip_mreqn *mreqn,
abi_ulong target_addr,
socklen_t len)
{
struct target_ip_mreqn *target_smreqn;

target_smreqn = lock_user(VERIFY_READ, target_addr, len, 1);
if (!target_smreqn)
return -TARGET_EFAULT;
mreqn->imr_multiaddr.s_addr = target_smreqn->imr_multiaddr.s_addr;
mreqn->imr_address.s_addr = target_smreqn->imr_address.s_addr;
if (len == sizeof(struct target_ip_mreqn))
mreqn->imr_ifindex = tswapal(target_smreqn->imr_ifindex);
unlock_user(target_smreqn, target_addr, 0);

return 0;
}

static inline abi_long target_to_host_sockaddr(int fd, struct sockaddr *addr,
abi_ulong target_addr,
socklen_t len)
Expand Down Expand Up @@ -2067,8 +2049,6 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
{
abi_long ret;
int val;
struct ip_mreqn *ip_mreq;
struct ip_mreq_source *ip_mreq_source;

switch(level) {
case SOL_TCP:
Expand Down Expand Up @@ -2111,19 +2091,40 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
break;
case IP_ADD_MEMBERSHIP:
case IP_DROP_MEMBERSHIP:
{
struct ip_mreqn ip_mreq;
struct target_ip_mreqn *target_smreqn;

QEMU_BUILD_BUG_ON(sizeof(struct ip_mreq) !=
sizeof(struct target_ip_mreq));

if (optlen < sizeof (struct target_ip_mreq) ||
optlen > sizeof (struct target_ip_mreqn))
optlen > sizeof (struct target_ip_mreqn)) {
return -TARGET_EINVAL;
}

ip_mreq = (struct ip_mreqn *) alloca(optlen);
target_to_host_ip_mreq(ip_mreq, optval_addr, optlen);
ret = get_errno(setsockopt(sockfd, level, optname, ip_mreq, optlen));
break;
target_smreqn = lock_user(VERIFY_READ, optval_addr, optlen, 1);
if (!target_smreqn) {
return -TARGET_EFAULT;
}
ip_mreq.imr_multiaddr.s_addr = target_smreqn->imr_multiaddr.s_addr;
ip_mreq.imr_address.s_addr = target_smreqn->imr_address.s_addr;
if (optlen == sizeof(struct target_ip_mreqn)) {
ip_mreq.imr_ifindex = tswapal(target_smreqn->imr_ifindex);
optlen = sizeof(struct ip_mreqn);
}
unlock_user(target_smreqn, optval_addr, 0);

ret = get_errno(setsockopt(sockfd, level, optname, &ip_mreq, optlen));
break;
}
case IP_BLOCK_SOURCE:
case IP_UNBLOCK_SOURCE:
case IP_ADD_SOURCE_MEMBERSHIP:
case IP_DROP_SOURCE_MEMBERSHIP:
{
struct ip_mreq_source *ip_mreq_source;

if (optlen != sizeof (struct target_ip_mreq_source))
return -TARGET_EINVAL;

Expand All @@ -2134,7 +2135,7 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
ret = get_errno(setsockopt(sockfd, level, optname, ip_mreq_source, optlen));
unlock_user (ip_mreq_source, optval_addr, 0);
break;

}
default:
goto unimplemented;
}
Expand Down Expand Up @@ -2277,18 +2278,13 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
switch (optname) {
case ALG_SET_KEY:
{
char *alg_key = g_malloc(optlen);

char *alg_key = lock_user(VERIFY_READ, optval_addr, optlen, 1);
if (!alg_key) {
return -TARGET_ENOMEM;
}
if (copy_from_user(alg_key, optval_addr, optlen)) {
g_free(alg_key);
return -TARGET_EFAULT;
}
ret = get_errno(setsockopt(sockfd, level, optname,
alg_key, optlen));
g_free(alg_key);
unlock_user(alg_key, optval_addr, optlen);
break;
}
case ALG_SET_AEAD_AUTHSIZE:
Expand All @@ -2305,12 +2301,10 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
case TARGET_SOL_SOCKET:
switch (optname) {
case TARGET_SO_RCVTIMEO:
case TARGET_SO_SNDTIMEO:
{
struct timeval tv;

optname = SO_RCVTIMEO;

set_timeout:
if (optlen != sizeof(struct target_timeval)) {
return -TARGET_EINVAL;
}
Expand All @@ -2319,13 +2313,12 @@ static abi_long do_setsockopt(int sockfd, int level, int optname,
return -TARGET_EFAULT;
}

ret = get_errno(setsockopt(sockfd, SOL_SOCKET, optname,
ret = get_errno(setsockopt(sockfd, SOL_SOCKET,
optname == TARGET_SO_RCVTIMEO ?
SO_RCVTIMEO : SO_SNDTIMEO,
&tv, sizeof(tv)));
return ret;
}
case TARGET_SO_SNDTIMEO:
optname = SO_SNDTIMEO;
goto set_timeout;
case TARGET_SO_ATTACH_FILTER:
{
struct target_sock_fprog *tfprog;
Expand Down
1 change: 1 addition & 0 deletions linux-user/syscall_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ struct target_rtc_pll_info {

#define TARGET_FIFREEZE TARGET_IOWR('X', 119, abi_int)
#define TARGET_FITHAW TARGET_IOWR('X', 120, abi_int)
#define TARGET_FITRIM TARGET_IOWR('X', 121, struct fstrim_range)

/*
* Note that the ioctl numbers for FS_IOC_<GET|SET><FLAGS|VERSION>
Expand Down
5 changes: 5 additions & 0 deletions linux-user/syscall_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ STRUCT(file_clone_range,
TYPE_ULONGLONG, /* src_length */
TYPE_ULONGLONG) /* dest_offset */

STRUCT(fstrim_range,
TYPE_ULONGLONG, /* start */
TYPE_ULONGLONG, /* len */
TYPE_ULONGLONG) /* minlen */

STRUCT(fiemap_extent,
TYPE_ULONGLONG, /* fe_logical */
TYPE_ULONGLONG, /* fe_physical */
Expand Down
4 changes: 2 additions & 2 deletions linux-user/uaccess.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void *lock_user(int type, abi_ulong guest_addr, ssize_t len, bool copy)
return NULL;
}
host_addr = g2h_untagged(guest_addr);
#ifdef DEBUG_REMAP
#ifdef CONFIG_DEBUG_REMAP
if (copy) {
host_addr = g_memdup(host_addr, len);
} else {
Expand All @@ -24,7 +24,7 @@ void *lock_user(int type, abi_ulong guest_addr, ssize_t len, bool copy)
return host_addr;
}

#ifdef DEBUG_REMAP
#ifdef CONFIG_DEBUG_REMAP
void unlock_user(void *host_ptr, abi_ulong guest_addr, ssize_t len)
{
void *host_ptr_conv;
Expand Down
4 changes: 4 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2350,6 +2350,7 @@ config_host_data.set('CONFIG_DEBUG_GRAPH_LOCK', get_option('debug_graph_lock'))
config_host_data.set('CONFIG_DEBUG_MUTEX', get_option('debug_mutex'))
config_host_data.set('CONFIG_DEBUG_STACK_USAGE', get_option('debug_stack_usage'))
config_host_data.set('CONFIG_DEBUG_TCG', get_option('debug_tcg'))
config_host_data.set('CONFIG_DEBUG_REMAP', get_option('debug_remap'))
config_host_data.set('CONFIG_LIVE_BLOCK_MIGRATION', get_option('live_block_migration').allowed())
config_host_data.set('CONFIG_QOM_CAST_DEBUG', get_option('qom_cast_debug'))
config_host_data.set('CONFIG_REPLICATION', get_option('replication').allowed())
Expand Down Expand Up @@ -4277,6 +4278,9 @@ if config_all_accel.has_key('CONFIG_TCG')
endif
summary_info += {'TCG plugins': get_option('plugins')}
summary_info += {'TCG debug enabled': get_option('debug_tcg')}
if have_linux_user or have_bsd_user
summary_info += {'syscall buffer debugging support': get_option('debug_remap')}
endif
endif
summary_info += {'target list': ' '.join(target_dirs)}
if have_system
Expand Down
2 changes: 2 additions & 0 deletions meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ option('plugins', type: 'boolean', value: false,
description: 'TCG plugins via shared library loading')
option('debug_tcg', type: 'boolean', value: false,
description: 'TCG debugging')
option('debug_remap', type: 'boolean', value: false,
description: 'syscall buffer debugging support')
option('tcg_interpreter', type: 'boolean', value: false,
description: 'TCG with bytecode interpreter (slow)')
option('safe_stack', type: 'boolean', value: false,
Expand Down
3 changes: 3 additions & 0 deletions scripts/meson-buildoptions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ meson_options_help() {
printf "%s\n" ' --enable-debug-graph-lock'
printf "%s\n" ' graph lock debugging support'
printf "%s\n" ' --enable-debug-mutex mutex debugging support'
printf "%s\n" ' --enable-debug-remap syscall buffer debugging support'
printf "%s\n" ' --enable-debug-stack-usage'
printf "%s\n" ' measure coroutine stack usage'
printf "%s\n" ' --enable-debug-tcg TCG debugging'
Expand Down Expand Up @@ -294,6 +295,8 @@ _meson_option_parse() {
--disable-debug-graph-lock) printf "%s" -Ddebug_graph_lock=false ;;
--enable-debug-mutex) printf "%s" -Ddebug_mutex=true ;;
--disable-debug-mutex) printf "%s" -Ddebug_mutex=false ;;
--enable-debug-remap) printf "%s" -Ddebug_remap=true ;;
--disable-debug-remap) printf "%s" -Ddebug_remap=false ;;
--enable-debug-stack-usage) printf "%s" -Ddebug_stack_usage=true ;;
--disable-debug-stack-usage) printf "%s" -Ddebug_stack_usage=false ;;
--enable-debug-tcg) printf "%s" -Ddebug_tcg=true ;;
Expand Down
2 changes: 1 addition & 1 deletion target/m68k/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
#define EXCP_MMU_ACCESS 58 /* MMU Access Level Violation Error */

#define EXCP_RTE 0x100
#define EXCP_HALT_INSN 0x101
#define EXCP_SEMIHOSTING 0x101

#define M68K_DTTR0 0
#define M68K_DTTR1 1
Expand Down
4 changes: 2 additions & 2 deletions target/m68k/m68k-semi.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ void do_m68k_semihosting(CPUM68KState *env, int nr)
args = env->dregs[1];
switch (nr) {
case HOSTED_EXIT:
gdb_exit(env->dregs[0]);
exit(env->dregs[0]);
gdb_exit(env->dregs[1]);
exit(env->dregs[1]);

case HOSTED_OPEN:
GET_ARG(0);
Expand Down
14 changes: 2 additions & 12 deletions target/m68k/op_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,8 @@ static void cf_interrupt_all(CPUM68KState *env, int is_hw)
/* Return from an exception. */
cf_rte(env);
return;
case EXCP_HALT_INSN:
if (semihosting_enabled((env->sr & SR_S) == 0)
&& (env->pc & 3) == 0
&& cpu_lduw_code(env, env->pc - 4) == 0x4e71
&& cpu_ldl_code(env, env->pc) == 0x4e7bf000) {
env->pc += 4;
do_m68k_semihosting(env, env->dregs[0]);
return;
}
cs->halted = 1;
cs->exception_index = EXCP_HLT;
cpu_loop_exit(cs);
case EXCP_SEMIHOSTING:
do_m68k_semihosting(env, env->dregs[0]);
return;
}
}
Expand Down

0 comments on commit 5da7219

Please sign in to comment.